Search for a command to run...
Used to display textual user input from keyboard.
npx shadcn@latest add @zaidan/kbdpnpx shadcn add @zaidan/kbdyarn dlx shadcn@latest add @zaidan/kbdbunx shadcn@latest add @zaidan/kbdCopy and paste the following code into your project.
1import type { ComponentProps } from "solid-js";2import { splitProps } from "solid-js";3
4import { cn } from "~/lib/utils";5
6type KbdProps = ComponentProps<"kbd">;7
8const Kbd = (props: KbdProps) => {9 const [local, others] = splitProps(props, ["class"]);10
11 return (12 <kbd13 class={cn(14 "pointer-events-none z-kbd inline-flex select-none items-center justify-center",15 local.class,16 )}17 data-slot="kbd"18 {...others}19 />20 );21};22
23type KbdGroupProps = ComponentProps<"div">;24
25const KbdGroup = (props: KbdGroupProps) => {26 const [local, others] = splitProps(props, ["class"]);27
28 return (29 <div30 class={cn("z-kbd-group inline-flex items-center", local.class)}31 data-slot="kbd-group"32 {...others}33 />34 );35};36
37export { Kbd, KbdGroup };Here are the source code of all the examples from the preview page:
import { Kbd } from "~/components/ui/kbd";function KbdBasic() { return ( <Example title="Basic"> <div class="flex items-center gap-2"> <Kbd>Ctrl</Kbd> <Kbd>⌘K</Kbd> <Kbd>Ctrl + B</Kbd> </div> </Example> );}import { Kbd } from "~/components/ui/kbd";function KbdModifierKeys() { return ( <Example title="Modifier Keys"> <div class="flex items-center gap-2"> <Kbd>⌘</Kbd> <Kbd>C</Kbd> </div> </Example> );}Use the KbdGroup component to group keyboard keys together.
import { Kbd, KbdGroup } from "~/components/ui/kbd";function KbdGroupExample() { return ( <Example title="KbdGroup"> <KbdGroup> <Kbd>Ctrl</Kbd> <Kbd>Shift</Kbd> <Kbd>P</Kbd> </KbdGroup> </Example> );}import { Kbd } from "~/components/ui/kbd";function KbdArrowKeys() { return ( <Example title="Arrow Keys"> <div class="flex items-center gap-2"> <Kbd>↑</Kbd> <Kbd>↓</Kbd> <Kbd>←</Kbd> <Kbd>→</Kbd> </div> </Example> );}import { ArrowLeft, ArrowRight, CircleDashed } from "lucide-solid";import { Kbd, KbdGroup } from "~/components/ui/kbd";function KbdWithIcons() { return ( <Example title="With Icons"> <KbdGroup> <Kbd> <CircleDashed /> </Kbd> <Kbd> <ArrowLeft /> </Kbd> <Kbd> <ArrowRight /> </Kbd> </KbdGroup> </Example> );}import { ArrowLeft, CircleDashed } from "lucide-solid";import { Kbd, KbdGroup } from "~/components/ui/kbd";function KbdWithIconsAndText() { return ( <Example title="With Icons and Text"> <KbdGroup> <Kbd> <ArrowLeft /> Left </Kbd> <Kbd> <CircleDashed /> Voice Enabled </Kbd> </KbdGroup> </Example> );}You can use the Kbd component inside a InputGroupAddon component to display a keyboard key inside an input group.
import { InputGroup, InputGroupAddon, InputGroupInput } from "~/components/ui/input-group";import { Kbd } from "~/components/ui/kbd";function KbdInInputGroup() { return ( <Example title="InputGroup"> <InputGroup> <InputGroupInput /> <InputGroupAddon align="inline-end"> <Kbd>Space</Kbd> </InputGroupAddon> </InputGroup> </Example> );}You can use the Kbd component inside a Tooltip component to display a tooltip with a keyboard key.
import { Save } from "lucide-solid";import { Button } from "~/components/ui/button";import { Kbd } from "~/components/ui/kbd";import { Tooltip, TooltipContent, TooltipTrigger } from "~/components/ui/tooltip";function KbdInTooltip() { return ( <Example title="Tooltip"> <Tooltip> <TooltipTrigger as={Button} size="icon-sm" variant="outline"> <Save /> </TooltipTrigger> <TooltipContent class="pr-1.5"> <div class="flex items-center gap-2"> Save Changes <Kbd>S</Kbd> </div> </TooltipContent> </Tooltip> </Example> );}import { Kbd } from "~/components/ui/kbd";function KbdWithSamp() { return ( <Example title="With samp"> <Kbd> <samp>File</samp> </Kbd> </Example> );}Use the Kbd component to display a keyboard key.
| Prop | Type | Default |
|---|---|---|
class | string | `` |
<Kbd>Ctrl</Kbd>Use the KbdGroup component to group Kbd components together.
| Prop | Type | Default |
|---|---|---|
class | string | `` |
<KbdGroup> <Kbd>Ctrl</Kbd> <Kbd>B</Kbd></KbdGroup>