shadcn.io is not affiliated with official shadcn/ui
Shadcn Link Overlay for React and Tailwind
Makes the whole card or article clickable.
This sofa is perfect for modern tropical spaces, baroque inspired spaces.
Living room SofaInstallation
bunx --bun shadcn@latest add https://kit.dev/r/link-overlay.jsonpnpm dlx shadcn@latest add https://kit.dev/r/link-overlay.jsonnpx shadcn@latest add https://kit.dev/r/link-overlay.jsonyarn shadcn@latest add https://kit.dev/r/link-overlay.jsonInstall the following dependencies:
bun add @ark-ui/reactpnpm add @ark-ui/reactnpm install @ark-ui/reactyarn add @ark-ui/reactCopy and paste the following code into your project.
"use client";
import { ark } from "@ark-ui/react/factory";
import type React from "react";
import { cn } from "@/lib/utils";
export const LinkBox = (props: React.ComponentProps<typeof ark.div>) => {
const { className, ...rest } = props;
return (
<ark.div
className={cn(
"relative",
"[&_a[href]:not([data-slot=link-overlay])]:relative [&_a[href]:not([data-slot=link-overlay])]:z-1",
className
)}
data-slot="link-box"
{...rest}
/>
);
};
export const LinkOverlay = (props: React.ComponentProps<typeof ark.a>) => {
const { className, ...rest } = props;
return (
<ark.a
className={cn(
"static",
"-mx-1 -my-0.5 px-1 py-0.5",
"rounded-md border border-transparent",
"before:absolute before:inset-0 before:z-0 before:block before:h-full before:w-full before:cursor-inherit before:content-['']",
"outline-none focus-visible:border-primary focus-visible:ring-[3px] focus-visible:ring-ring/32",
className
)}
data-slot="link-overlay"
{...rest}
/>
);
};Update the import paths to match your project setup.
Usage
import { Button } from "@/components/ui/button";
import {
Card,
CardFooter,
CardHeader,
CardMedia,
CardTitle,
} from "@/components/ui/card";
import { LinkBox, LinkOverlay } from "@/components/ui/link-overlay";<LinkBox asChild>
<Card className="w-full max-w-xs">
<CardMedia className="h-32 bg-muted" variant="image" />
<CardHeader description="This sofa is perfect for modern tropical spaces, baroque inspired spaces.">
<LinkOverlay asChild>
<CardTitle asChild>
<a href="#">Living room Sofa</a>
</CardTitle>
</LinkOverlay>
</CardHeader>
<CardFooter className="flex-row-reverse gap-2">
<Button className="flex-1">Buy now</Button>
<Button className="flex-1" variant="outline">
Add to cart
</Button>
</CardFooter>
</Card>
</LinkBox>Accessibility
| Key | Description |
|---|---|
Enter | Activate the focused control. |
Space | Activate the focused control. |
Demos
Article
With Link
API Reference
LinkOverlay
a
PropType
AttributeType
LinkBox
div
PropType
AttributeType