Kbd
Displays a keyboard key or a combination of keys.
Installation
Needs the arene setup first.
Install the packages it imports:
Set up the token layer and the StyleX compiler, if you have not already. See
Installation, and paste states.ts from the same page.
The keycap's surface comes from it. Kbd also needs interop.css, which sizes
an icon inside a key.
Paste this source into the file named in its title.
Change the @/ imports if your project uses different aliases.
Usage
Group
Wrap keys pressed together in KbdGroup. It renders a kbd of kbds, which
is how HTML marks up a combination, and sits inline in running text.
Use ⌘K to open the command palette, or Esc to close it.
Input group
Put a shortcut at the end of a search field with an InputGroupAddon.
API reference
Pass render to replace a part's element or compose it with another component.
Both parts render a kbd through Base UI's
useRender, and take xstyle,
className and inline style alongside every kbd attribute.
Kbd
| Prop | Type | Default |
|---|---|---|
render | ReactElement | ((props, state) => ReactElement) | <kbd /> |
xstyle | StyleXStyles | — |
className | string | — |
A flat keycap, 1.25rem tall and at least as wide, in the monospace face. It
is not focusable.
KbdGroup
An inline row of keys with a 0.25rem gap. Text between keys, such as a +,
sits in the same row.
kbdStyles
The style maps behind the component. Spread them onto any element.
| Key | What it is |
|---|---|
base | The cap: fill, hairline, size and type |
group | The inline row |
Data attributes
| Attribute | On | Effect |
|---|---|---|
data-slot="kbd" | a key | Targets a key from a parent |
data-slot="kbd-group" | the group | Targets the group from a parent |
CSS variables
| Variable | On | Effect |
|---|---|---|
--arene-icon-size | a key | The icon's size, read by interop.css. Defaults to 12px |