# Keyboard input

A key cap that shows a keyboard shortcut in a line of text, a menu row or a button.

This is the HTML to build it with `dex.css`, for work outside the Dex codebase. Read https://brand.meetdex.ai/design.md first: it says how to set up a page and how to use the stylesheet. The page at https://brand.meetdex.ai/components/kbd shows the Dex app's own React component, which only works inside the Dex codebase.

## HTML

```html
<kbd class="dex-kbd">Esc</kbd>
<kbd class="dex-kbd">⌘K</kbd>
<kbd class="dex-kbd">⇧⌘P</kbd>
```

- **Modifiers**: on Apple devices they're symbols in the order ⌃ ⌥ ⇧ ⌘, written together with the key: "⌘K", "⇧⌘P". Elsewhere they're words in the order Ctrl, Alt, Shift: "Ctrl K", "Ctrl Shift P". Show the one for the reader's platform; in a static mock, show the Apple form.
- **In a button**: the cap takes a tint of the button's text, so it doesn't read as a second button. Hide it from screen readers and put the shortcut on the button.

```html
<button class="dex-button dex-button--outline" aria-keyshortcuts="Meta+K">
  Search <kbd class="dex-kbd" aria-hidden="true">⌘K</kbd>
</button>
```

- **In a menu**: a cap at the end of a `dex-menu-item`, before its tick, with `aria-hidden="true"`, and `aria-keyshortcuts` on the item.
- **In a tooltip**: a cap inside a `dex-tooltip` takes the tooltip's colours by itself.
- **In prose**: leave the cap readable, so a screen reader hears the keys: "Press <kbd class="dex-kbd">⌘K</kbd> to search."

## Rules

- Inside a control, the cap is `aria-hidden="true"` and the control carries `aria-keyshortcuts`, so the shortcut isn't read out as part of the label.
- In a line of text, the cap stays readable.
- Use the real key names: Esc, Enter, Tab, Space, the arrows (↑ ↓ ← →).
