Ir al contenido
Español

Cómo funciona

Renders the semantic nesting browsers expect: an outer kbd for the shortcut and one inner kbd per key. A raised cap is a faint vertical gradient with a hairline and a 2px skirt drawn as an inset shadow, so it reads as a physical key without a heavy border; glyph keys are square and word keys get side padding. Pressing a cap sinks the face by the skirt height on a short spring and tints it with the accent. In the demo the rows play their shortcuts in turn, and pressing keys on your own keyboard lights the matching row.

Úsalo para

  • Shortcut hints in menus, tooltips, command palettes and help pages.
  • Onboarding that teaches a shortcut by showing the keys being pressed.

Busca otra opción cuando

  • Touch-only interfaces where there is no keyboard to press.

Uso

import { Kbd } from './Kbd.jsx'

const isApple = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform)

export function SearchHint() {
  return (
    <p>
      Press <Kbd shortcut="mod+k" platform={isApple ? 'mac' : 'other'} /> to search, or <Kbd shortcut="g then i" /> for the inbox.
    </p>
  )
}

Propiedades

PropiedadTipoPor defectoQué hace
shortcutstring | string[][]—Keys joined with + and steps with “then” or a comma: 'mod+shift+p', 'g then i'. Named keys: mod, cmd, ctrl, alt, shift, enter, esc, tab, backspace, space and the four arrows; other keys show as typed, single letters upper-cased.
childrenReactNode—Without shortcut, a single cap with your own content.
platform'mac' | 'other''mac'Apple glyphs (⌘ ⌥ ⇧) or words (Ctrl, Alt, Shift); mod maps to Command or Ctrl. Decide it after mount to avoid a hydration mismatch.
size / variant'sm' | 'md' | 'lg' / 'raised' | 'flat''md' / 'raised'22, 26 or 40px caps; raised has a physical skirt, flat is a quiet chip for menus.
pressedboolean | string[]falseSinks every cap, or only the listed keys.
thenLabelstring'then'Word between steps, shown and spoken.

Accesibilidad

  • The outer kbd carries an aria-label with spoken key names (“Command Shift P”), because glyphs such as ⌘ are read inconsistently; the caps themselves are hidden from screen readers.
  • The word between steps is part of the spoken label.
  • Caps are not interactive; pressing state is visual only.
  • Reduced motion keeps the colour change and removes the sink.

Movimiento

Press: 140ms spring sink by the skirt height with a colour fade.

Añádelo a tu proyecto

Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.

Kbd.jsxkbd.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Datos
Diferencias de código viene con Pro. La vista previa aparece al desbloquearlo.
Cuenta atrás con flip viene con Pro. La vista previa aparece al desbloquearlo.