# Kbd

A keyboard key or shortcut shown as a keycap in help text, menus and tooltips.

- Family: display
- Import: `import { Kbd } from "@senvenli/react/display";`
- Page: https://design.senvenli.com/docs/components/kbd
- JSON: https://design.senvenli.com/docs/components/kbd.json

## Example: A key in help text

One key per Kbd, in running text.

```tsx
import { Kbd, Text } from "@senvenli/react/display";

export default function Example() {
  return (
    <Text>
      Press <Kbd>Esc</Kbd> to close the panel.
    </Text>
  );
}
```

## Examples

### A shortcut

`isModifier` shows ⌘ on Apple devices and Ctrl elsewhere.

```tsx
import { Kbd, Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";

export default function Example() {
  return (
    <Stack direction="horizontal" space="space-100">
      <Text>Search orders</Text>
      <Stack direction="horizontal" space="space-050">
        <Kbd isModifier />
        <Kbd>K</Kbd>
      </Stack>
    </Stack>
  );
}
```

### Glyph keys

A screen reader may skip a glyph, so `label` says the key's name.

```tsx
import { Kbd, Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";

export default function Example() {
  return (
    <Stack direction="horizontal" space="space-100">
      <Text>Add a line break</Text>
      <Stack direction="horizontal" space="space-050">
        <Kbd label="Shift">⇧</Kbd>
        <Kbd label="Enter">↵</Kbd>
      </Stack>
    </Stack>
  );
}
```

## Guidelines

### When to use it

- Telling people which key or shortcut does something.

### Use something else when

- [badge](https://design.senvenli.com/docs/components/badge.md): The label is a status, not a key.
- [text](https://design.senvenli.com/docs/components/text.md): Code or a value is shown, not a key to press.

## Accessibility

Built in:

- Kbd isModifier shows ⌘ on Apple platforms and Ctrl elsewhere.

You provide:

- A `label` for glyph keys a screen reader may skip ("Command" for ⌘).

## API reference

### Kbd

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| children | `React.ReactNode` |  | no | One key per Kbd; a shortcut is several Kbd separated by a space. Left out with `isModifier`. |
| isModifier | `boolean` |  | no | The platform's shortcut modifier: ⌘ on Apple platforms, Ctrl elsewhere (Ctrl on the server, settled after mount). |
| label | `string` |  | no | What a screen reader says instead of a glyph it may skip ("Command" for ⌘); the glyph is then hidden. |

### Tokens it reads

`--ds-border`, `--ds-border-bold`, `--ds-radius-xsmall`, `--ds-surface-raised`, `--ds-text-subtle`, `--font-ds-mono`
