videorc/ui

Kbd

Videorc's key chip, a glass keycap with a bright top edge and a dark bottom edge. Inside a filled button it takes the button's own ink instead.

↑↓Move between questions

EscDismiss Buddy’s proposed post

Installation

$ pnpm dlx shadcn@latest add @videorc/kbd

Usage

import { Kbd, KbdGroup } from "@/components/ui/kbd";
<Kbd>Esc</Kbd>

Kbd draws a key. A shortcut goes through Shortcut keys, which prints it the way the reader's platform does and draws this chip: never type a modifier glyph or "Cmd+" by hand.

Examples

In a button

Inside a default, destructive or record button the gray keycap reads at under 3:1, so there the chip takes the button's text colour on a faint fill of it, with no glass. It matches by ancestry: nothing to remember at the call site.

Theming

Token or attributeMeaning
glass-keycapThe keycap: a gradient fill, a rim, a bright top edge and a dark bottom edge
--keycap-fill-top, --keycap-fill-bottom, --keycap-rimThe keycap's fill and rim, per theme
--keycap-highlight, --keycap-baseIts top and bottom edges
rounded-chipThe 6 px chip radius
KBD_ON_FILLED_BUTTONThe classes for a chip inside a filled button, exported

Accessibility

Kbd is a <kbd> element, and KbdGroup a <span> that spaces several. Screen readers read the text inside, so pair a key with words that say what it does ("Move between questions"), and give a control its shortcut with aria-keyshortcuts (shortcutAriaKeys from @/lib/platform).

API reference

Kbd

Every kbd prop.

KbdGroup

Every span prop.