# Kbd

A keyboard shortcut hint rendered as a native kbd element. KbdGroup arranges the separate keys in a shortcut sequence. These components display shortcuts without registering keyboard handlers.

**Dependencies:** npm: 1 direct, 2 total; registry: 2 direct, 2 total.

Native: iOS stable, Android stable.

## Usage

### When to use

- Show a keyboard shortcut beside the action it activates.
- Describe a sequence of keys in instructions.

### When not to use

- An interactive key or action. Use Button.
- Registering a keyboard shortcut. Add the handler in your application.

### Native

**Shortcut**

```text
HStack { WerewolfKbd { Text("⌘") }; WerewolfKbd { Text("K") } }
```

```text
Row { WerewolfKbd { Text("⌘") }; WerewolfKbd { Text("K") } }
```

**Small**

```text
WerewolfKbd(size: .sm) { Text("Esc") }
```

```text
WerewolfKbd(size = WerewolfKbdSize.Sm) { Text("Esc") }
```

## Variants

### size

Compact shortcut hint: sm is 16px tall and md is 20px tall. Both use 12px UI text.

Values: `sm`, `md`. Default: `md`.

## Examples

### Shortcut sequence

```tsx
<KbdGroup aria-label="Command K">
  <Kbd aria-label="Command">⌘</Kbd>
  <Kbd>K</Kbd>
</KbdGroup>
```

### Beside an action

```tsx
<Button variant="secondary">
  <span>Open search</span>
  <KbdGroup aria-label="Control K">
    <Kbd size="sm" aria-label="Control">Ctrl</Kbd>
    <Kbd size="sm">K</Kbd>
  </KbdGroup>
</Button>
```

## Do and don't

### Do

- Render each key in its own Kbd and combine keys with KbdGroup.
- Use readable names for symbols that assistive technology may pronounce ambiguously.

### Don't

- Do not make Kbd clickable or focusable.
- Do not display a shortcut that the application does not support.

## Props

| Name | Type | Values | Default | Description |
| --- | --- | --- | --- | --- |
| `size` | `enum` | `sm`, `md` | `md` | Compact shortcut hint: sm is 16px tall and md is 20px tall. Both use 12px UI text. |

Not generated: KbdGroup.

### Slots

| Name | Required | Description |
| --- | --- | --- |
| `children` | yes | Key label or shortcut symbol. |

## Anatomy

| Part | Description |
| --- | --- |
| `root` | Compact native kbd with UI type, surface fill, neutral border and secondary text. Small is 16px tall, medium is 20px tall; each has the same minimum width and grows for longer key names. |
| `group` | Inline KbdGroup wrapper with token spacing between keys. |

## Accessibility

Role: `none`

- Kbd is not focusable and does not take keyboard input.
- Give shortcut symbols readable names, such as aria-label="Command" for ⌘.
- A displayed shortcut is only a hint. The application owns shortcut handling.

## Install

```bash
npx werewolf-ui add kbd
```

Run `npx werewolf-ui init` once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See [Installation](https://www.werewolf-ui.dev/docs/installation.md) for requirements and the alternative registry setup.

```bash
npx werewolf-ui add kbd --platform ios
npx werewolf-ui add kbd --platform android
```

For iOS and Android, run `npx werewolf-ui init --platform ios` or `npx werewolf-ui init --platform android` once, then add with `--platform`. See [Installation](https://www.werewolf-ui.dev/docs/installation.md).
