Content
Keyboard key
A key or keyboard shortcut in running text.
Example
cr-kbd draws a keyboard key in running text, help or a menu. The content is the key name: <CrKbd>Enter</CrKbd>.
For a shortcut of several keys, keys separates them with +: keys="Mod+K". Mod becomes ⌘ on Mac and Ctrl elsewhere; Alt, Shift and Ctrl become ⌥, ⇧ and ⌃ on Mac. A single letter is uppercased.
Open the command palette with
Undo the last action:
'use client';
import { CrBox, CrKbd } from '@cristal-ui/react';
export default function KbdBasic() {
return (
<CrBox display="flex" direction="column" gap="sm" align="start">
<p style={{ margin: 0 }}>
Open the command palette with <CrKbd keys="Mod+K" />, then confirm with <CrKbd>Enter</CrKbd>.
</p>
<p style={{ margin: 0 }}>
Undo the last action: <CrKbd keys="Mod+Z" />; redo it: <CrKbd keys="Mod+Shift+Z" />.
</p>
</CrBox>
);
}Accessibility
- Each key is a
kbdelement, and a shortcut is akbdgrouping them, as HTML specifies. - Mac symbols are hidden from screen readers, which read their name instead ("Command + K").
- The key is text: it grows with the size of the surrounding text.
API
Properties
| Property | Type | Default | Description |
|---|---|---|---|
keys | string | — | Raccourci, touches séparées par + : « Mod+K », « Shift+Alt+P ». Mod, Ctrl, Alt et Shift s'adaptent au système. |
Slots
| Slot | Description |
|---|---|
| default | Une touche, quand keys n'est pas donné. |
CSS parts
To style it from outside: cr-kbd::part(name) { … }
| Part | Description |
|---|---|
key | Chaque touche. |