Component
Kbd
A keyboard key or shortcut.
Press⌘Kto search, or D to switch theme.
Installation
npx shadcn@latest add @doffy/kbdOr, without the registry in components.json:
npx shadcn@latest add https://ui.doffy.com/r/kbd.jsonUsage
import { Kbd, KbdGroup } from "@/components/ui/kbd"
export default function KbdDemo() {
return (
<p className="flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground">
Press
<KbdGroup>
<Kbd>⌘</Kbd>
<Kbd>K</Kbd>
</KbdGroup>
to search, or <Kbd>D</Kbd> to switch theme.
</p>
)
}
Source
ShowHide kbd.tsx
import { cn } from "cn"
function Kbd({ className, ...props }: React.ComponentProps<"kbd">) {
return (
<kbd
data-slot="kbd"
className={cn(
"pointer-events-none inline-flex h-5 w-fit min-w-5 items-center justify-center gap-1 rounded-none bg-muted px-1 font-sans text-xs font-medium text-muted-foreground select-none in-data-[slot=tooltip-content]:bg-background/20 in-data-[slot=tooltip-content]:text-background dark:in-data-[slot=tooltip-content]:bg-background/10 [&_svg:not([class*='size-'])]:size-3",
className
)}
{...props}
/>
)
}
function KbdGroup({ className, ...props }: React.ComponentProps<"div">) {
return (
<kbd
data-slot="kbd-group"
className={cn("inline-flex items-center gap-1", className)}
{...props}
/>
)
}
export { Kbd, KbdGroup }