Prevent Link click when button inside is being clicked
Unanswered
DieZitrone posted this in #help-forum
My component
I wont to be able to click the button without being redirected by the link
I wont to be able to click the button without being redirected by the link
<Link
href={`/dashboard/ideas/${post.id}`}
key={post.id}
className="h-[35rem] w-[19rem] bg-gray-300 rounded-xl flex flex-col px-2 pb-2 group/card hover:-translate-y-2 transition-all cursor cursor-pointer text-white "
>
<div className="p-1.5 group-hover/card:-translate-y-1 transition-all flex flex-row justify-center">
<div className="h-4 w-4 bg-gray-900 rounded-full z-20"></div>
</div>
<div className="bg-gradient-to-tr from-[#170E13] to-[#7A7ADB] h-full w-full rounded-xl flex flex-col justify-between relative group-hover/card:-translate-y-2 transition-all">
<div className="absolute bottom-12 right-4">
<div className="flex flex-col items-center gap-2 z-10">
{postState.is_liked ? (
<button>
<FaHeart
onClick={async (e) => {
await updatePostLike(!postState.is_liked);
}}
size="25px"
/>
</button>
) : (
<button>
<BiHeart
onClick={async (e) => {
await updatePostLike(!postState.is_liked);
}}
size="25px"
/>
</button>
)}
<BiDotsVerticalRounded size="25px" />
</div>
</div>
<div></div>
<div className="flex flex-row justify-center p-2 text-center">
<h3>"{postState.title}"</h3>
</div>
</div>
</div>
</Link>14 Replies
Sun bear
can you send a picture of the card?
the heart is the clickable button
If you click anywhere else on the card he wanted them to be redirected.
Can this be achieved by changing the z-index of the heart button?
@Berlim Can this be achieved by changing the z-index of the heart button?
Good idea for him to try. Ive never tried to do something like this so Im also curious
Tried the z index, no change
I also tried that xD
Munchkin
yeah i think that Link messes that up.
You could try to remove link and make it a button as well and when you click on it you redirect using href.
You could try to remove link and make it a button as well and when you click on it you redirect using href.
Button can’t be a child of a button.
Well <a> can’t be a child of <a>
Australian Freshwater Crocodile
Why not have a div that will have the video and the link, then an other div on top of it (absolute position) where you have your layout. then wrap them both with a div with a relative position.