Command palette

@yasinsensoy/web

Web · Components

Kbd

A keyboard key or shortcut.

3 exports

Live example

Preview

Press Control+Shift+P to open commands.

Code

import { Kbd } from "@yasinsensoy/web";

<Kbd keys="Mod+Shift+P" />

Events

  1. Events appear here when you interact with the preview.

Key sequence and hand-written key

Go to dashboard: G, DSend: Control+EnterEsc

Import

import { Kbd } from "@yasinsensoy/web";

Kbd

componentClient component

A keyboard key or shortcut. The shortcut is given with keys and written per the user's operating system: "⌘K" on macOS/iOS, "Ctrl+K" on Windows/Linux. Uses the same notation as menu and CommandPalette shortcuts.

  • Screen readers read key names, not symbols ("Meta+K").
  • On the server and on first render it is written in the Windows format, then updated for the real system; there is no hydration mismatch.
  • To hide it on touch devices use className="pointer-coarse:hidden".
Kbd({ keys, children, split, variant: variantProp, size, className, ...props }: KbdProps): JSX.Element

Examples

<Kbd keys="Mod+K" />
<Kbd keys="Mod+Shift+P" split />
<p>Press <Kbd keys="Mod+S" variant="soft" size="sm" /> to save.</p>
<Kbd>Enter</Kbd>

Look of the key box.

  • outline: bordered with a thick bottom edge; looks like a real key.
  • soft: borderless, pale background; plain in menus and tooltips.
  • ghost: text only; inside buttons.
type KbdVariant = "outline" | "soft" | "ghost"

KbdProps

interface

Props of the Kbd component.

Extends: Omit<ComponentProps<"kbd">, "children">

NameTypeDefaultDescription
keys?stringShortcut to show: "Mod+K", "Mod+Shift+P", "Alt+Enter", "Esc". Mod is written as ⌘ on macOS/iOS and Ctrl on other systems. For a key sequence (e.g. G then D) separate with a space: "G D". If omitted, children is shown as is.
children?ReactNodeManually written content instead of keys (e.g. "Enter").
split?booleanfalseShow each key in a separate box? If false, the whole shortcut is in one box (e.g. "⇧⌘P" or "Ctrl+Shift+P").
variant?KbdVariant | CustomVariant<"kbd">"outline"Appearance: built-in (KbdVariant) or a custom appearance added with defineAppearance. If omitted, UIProvider appearance.defaults.kbd.variant.
size?"sm" | "md""md"Size.