Kbd

Keyboard hint chip for shortcuts and key chords.

Also known as: keyboard shortcut, keycap, hotkey, shortcut chip, kbd

Installation

Install with the CLI, or copy the component source into your project.

Add kbd (npm)

npx --yes -p github:itsvigneshv/default-file-ui#main df-ui add kbd

Default

Keyboard hint chip at size sm.

Sizes

sm for menu slots. md for larger inline chrome.

sm
md

Chords

Compact Unicode chords for common shortcuts.

Anatomy

Compose KbdAbbr and KbdContent for explicit control.

K

In menu

Pass shortcut on DropdownMenuItem to render Kbd trailing.

In list

Kbd in List Item trailing.

Properties

Keyboard hint chip for shortcuts and key chords. Pass a compact Unicode string such as ⌘K, or compose KbdAbbr and KbdContent. Display only; the host owns bindings.

Kbd

PropTypeDefaultNotes
size"sm" | "md""sm"Chip density. sm for menu trailing slots. md for larger inline chrome.
childrenReactNode-Unicode chord such as ⌘K, or compose KbdAbbr and KbdContent. Textual forms such as Ctrl+K are not parsed.
aria-labelstring-Accessible name for the chip. Derived from string children when omitted. String-chord parts are presentational when a name is set.
classNamestring-Additional styles on the chip.
…HTML attributesComponentProps<"kbd">-Standard kbd element attributes.

KbdAbbr

PropTypeDefaultNotes
titlestring-Accessible expansion for the modifier or special key, such as Command for ⌘.
childrenReactNode-Unicode key glyph such as ⌘, ⇧, ⌥, or ⌫.
classNamestring-Additional styles on the abbr.

KbdContent

PropTypeDefaultNotes
kind"key" | "punct""key"key for Latin characters. punct for punctuation such as a comma.
childrenReactNode-Key label such as K, P, or ,.
classNamestring-Additional styles on the content span.

hasKbdShortcut

PropTypeDefaultNotes
valueunknown-Returns true when value is a non-empty shortcut string after trim.

Tokens

Theme defaults live on :root. Override these globally or on a local host.

TokenTypeDefaultNotes
--df-kbd-bgcolorvar(--df-neutral-100)Chip fill.
--df-kbd-fgcolorvar(--muted-foreground)Chord ink.
--df-kbd-radiusCSS lengthvar(--radius-sm)Corner radius.
--df-kbd-font-size-smCSS lengthvar(--df-text-xs)Type size at size sm.
--df-kbd-font-size-mdCSS lengthvar(--df-text-xs)Type size at size md.
--df-kbd-height-smCSS lengthcalc(5 * var(--spacing-unit))Chip height at size sm.
--df-kbd-height-mdCSS lengthcalc(5.5 * var(--spacing-unit))Chip height at size md.
--df-kbd-padding-inline-smCSS lengthcalc(2 * var(--spacing-unit))Horizontal padding at size sm.
--df-kbd-padding-inline-mdCSS lengthcalc(2.5 * var(--spacing-unit))Horizontal padding at size md.
--df-kbd-min-width-smCSS lengthcalc(5 * var(--spacing-unit))Minimum chip width at size sm.
--df-kbd-min-width-mdCSS lengthcalc(5.5 * var(--spacing-unit))Minimum chip width at size md.
--df-kbd-glyph-gapCSS length0.12emSpace between chord parts.
--df-kbd-mod-optical-shiftCSS length0emOptional vertical nudge for modifier abbrs. Defaults to 0.
--df-kbd-punct-optical-shiftCSS length0emOptional vertical nudge for punctuation content. Defaults to 0.