- Command palette⌘+K
- Save draft⌘+S
- Toggle sidebar⌘+⇧+B
- Close dialogEsc
GhostKbd
GhostKbd displays a keyboard key or shortcut combination with native <kbd> semantics. Import it from @ghostvue/themes for default keycap chrome. For the unstyled element and the useGhostKbd composable, see Advanced: headless composition.
Command shortcut sheet
Platform-switchable keyboard shortcut list rendered with themed GhostKbd keycaps.
A shortcut list in a GhostCard pairs each command with a themed GhostKbd combination from @ghostvue/themes. Pass the keys as an array of tokens, such as ['mod', 'shift', 'b'], and GhostKbd renders one keycap per key with a + between them. The "Keycap platform" GhostSegmentedControl previews both label sets: Apple shows ⌘ and ⇧ with abbr titles, and PC shows Ctrl and Shift. Each row wraps its keycaps under the command name when the card is narrow, and a combination keeps its keys together.
GhostKbd only displays the shortcut. Register the handler that runs the command elsewhere; see When not to use it.
Shortcuts in running text
Keycap chrome and size on the @ghostvue/themes wrapper.
Put GhostKbd inline in help text, menus, and tooltips. A slot-only instance, such as <GhostKbd size="sm">Esc</GhostKbd>, is itself a keycap. A keys combination drops chrome on the outer kbd and paints each nested key instead.
Importing the themed component loads the default stylesheet. Visual props exist only on this wrapper:
@ghostvue/themes adds these to the headless GhostKbd API, which it forwards:
| Prop | Type | Default | Description |
|---|---|---|---|
size | 'sm' | 'md' | 'lg' | "md" | Type and inset scale. The default omits data-size so CSS can treat a missing hook as md. |
The default omits data-size. Sizes use type and space tokens, not control minimums: GhostKbd is inline chrome, not a 40px action.
Combinations
Each token in keys becomes a nested <kbd data-part="key">. Separators are a literal +, so assistive technology reads "Control plus K". Use the default slot to append one more key after the tokens:
<GhostKbd :keys="['mod']">K</GhostKbd>Known tokens include mod, meta / command / cmd, ctrl / control, alt / option, shift, win / super, enter / return, esc / escape, tab, space, backspace, delete, and arrow keys. mod is the platform primary modifier (Command on Apple, Control on PC). meta is specifically Meta / Command / Windows and stays Win on PC. Unknown tokens render as given; a single letter is uppercased. Combinations are arrays — strings are not split on +.
Platform-aware labels
Pass platform="apple" or platform="pc" when the label set must not depend on the browser — documentation screenshots, SSR that should show Command, or a settings page that previews both, like the command shortcut sheet. 'auto' is for product UI that should match the reader.
'auto' never reads navigator during setup. Server HTML and the first client render use PC labels (Ctrl, Alt, Win). After mount, Apple browsers update to symbols (⌘, ⌥) with abbr titles. That sequence avoids a hydration mismatch.
When not to use it
- Listening for shortcuts.
GhostKbddoes not register hotkeys or run commands. Display the shortcut here; handle the key elsewhere. - A tooltip, menu, or command palette. Compose those from overlay primitives and put
GhostKbdinside them. - Translated prose for modifiers. Put the words in the slot and omit
keys, or pass already-localized tokens as unknown strings.
Accessibility and environment behavior
The component adds no role, no ARIA state, and no keyboard handling. Assistive technology reads the text inside the native kbd, including + separators and abbr titles on Apple symbols.
SSR markup is deterministic from props. 'auto' equals 'pc' until onMounted. Setup does not read browser globals. No listeners, timers, or observers require cleanup.
See the GhostKbd specification for the complete behavior and compatibility contract.
Advanced: headless composition
For teams that bring their own design system, GhostKbd from @ghostvue/vue renders the same native <kbd> markup and labels with no keycap chrome, and useGhostKbd resolves labels for markup you render yourself.
Basic use
Native kbd chrome for a single key.
The root is always a native <kbd>. Slot content is the ordinary way to show a single already-localized key.
Composable
Same contract as GhostKbd, applied to a native host.
useGhostKbd returns rootProps and the resolved keyItems. Render a nested kbd per item and a + separator between them.
Headless combination
Key tokens plus a trailing slot key.
Headless platform labels
Explicit Apple and PC modifier labels.
Styling
The unstyled component renders one native <kbd> with class ghost-kbd, data-part="root", and data-platform="apple" | "pc". Combinations add data-part="key" and data-part="separator". There is no data-state.
.ghost-kbd[data-platform='apple'] {
/* Applies after auto detection or an explicit apple platform. */
}You can also import the stylesheet and wrap unstyled kbd elements in .ghost-theme when you want a region of headless components to pick up the defaults. See the default theme guide.
API
| Prop | Type | Default | Description |
|---|---|---|---|
keys | readonly string[] | string | "[]" | Key tokens rendered as nested kbd elements. A string is one key; an array is a combination. Tokens are matched case-insensitively. Unknown tokens render as given, except a single letter is uppercased. |
platform | GhostKbdPlatform | "auto" | Modifier label set. auto uses PC labels until after mount, then Apple labels when the browser looks like Apple. Explicit apple and pc are deterministic from the prop. |
| Slot | Slot props | Description |
|---|---|---|
default | — | Key content. When keys is omitted, this is the entire kbd contents. When keys is set, this is appended after a plus separator as extra combination content. |
All native phrasing attributes and event listeners fall through to the root kbd. The default slot is the only content slot. When keys is set, the slot is appended after a + as extra combination content.
There is no model and no exposed focus() / blur() contract: this is display-only.