ComponentsDisplay
Kbd
A Kbd shows users the key or the shortcut that runs a command, such as ⌘K for search.
When to Use
- to show the shortcut of a control: at the end of a search field in an Input Group, in a Button, or in a Tooltip
- in a sentence that names a key to press, such as “Press ⌘ K to search”
When Not to Use
- for the shortcut of a menu item (use
DropdownMenuShortcutin a Dropdown Menu orCommandShortcutin Command)
Accessibility
Kbd and KbdGroup both render a kbd element, which is text and can’t receive focus. A Kbd shows a key but doesn’t bind one, so you handle the shortcut in the product.
Installation
npx shadcn@latest add @summit/kbdUsage
import { Kbd } from '@/components/ui/kbd';
<Kbd>⌘K</Kbd>;A Combination
To show a combination, place one Kbd for each key in a KbdGroup.
import { Kbd, KbdGroup } from '@/components/ui/kbd';
<KbdGroup>
<Kbd>⌘</Kbd>
<Kbd>K</Kbd>
</KbdGroup>;In a Button
To place a Kbd in a Button, mark it with data-icon="inline-end", as you would mark an icon. A Kbd ignores pointer events, so a click on it reaches the Button.
import { Button } from '@/components/ui/button';
<Button variant="outline">
Save
<Kbd data-icon="inline-end">⏎</Kbd>
</Button>;API Reference
Kbd and KbdGroup add no props. All props are passed to the kbd element.