Skip to main content

kbd

Used to display textual user input from keyboard.

Philosophy

Keyboard shortcuts deserve visual prominence. The Kbd component renders key combinations with consistent styling, making shortcut discovery a natural part of the UI rather than something hidden in documentation. We pair it with @gentleduck/vim for actual key binding - Kbd handles the display, vim handles the logic.

Installation


npx @gentleduck/cli add kbd

npx @gentleduck/cli add kbd

Usage

import { Kbd } from "@/components/ui/kbd"
<Kbd>Ctrl</Kbd>

Examples

Group

Use the KbdGroup component to group keyboard keys together.

Button

Use the Kbd component inside a Button component to display a keyboard key inside a button.

Tooltip

You can use the Kbd component inside a Tooltip component to display a tooltip with a keyboard key.

Input Group

You can use the Kbd component inside a InputGroupAddon component to display a keyboard key inside an input group.

RTL Support

Set the direction once with DirectionProvider (or <html dir="rtl">) and the surrounding layout follows it. Kbd and KbdGroup take their direction from their own label, so shortcuts such as Ctrl + S or ⌘K keep their order inside right-to-left text.

Motion

Use MotionKbd for a staggered scaleIn entrance (fade, scale, and blur) with a bouncy spring transition on keyboard shortcuts, powered by motion.

API Reference

Kbd

Displays an individual keyboard key with consistent styling.

PropTypeDefaultDescription
dir'ltr' | 'rtl' | 'auto''auto'Text direction. Defaults to auto, so it follows the key label rather than the page.
classNamestring-Additional class names for the kbd element
keysstring-Raw key combo string formatted for display via @gentleduck/vim's formatForDisplay. Used as a fallback when children is not provided.
childrenReact.ReactNode-Key label text or icon. Takes precedence over keys when both are provided.
...propsReact.HTMLProps<HTMLElement>-Additional props to spread to the kbd element

KbdGroup

Groups multiple Kbd components together in an inline layout.

PropTypeDefaultDescription
classNamestring-Additional class names for the group
childrenReact.ReactNode-Kbd elements to group together
...propsReact.ComponentPropsWithoutRef<'div'>-Additional props to spread to the group element (renders as a kbd)

MotionKbd

Same props as Kbd plus an optional index prop for stagger delay (30ms per index). Adds a scaleIn entrance (fade, scale, and blur) with a bouncy spring transition. Requires the motion package.