Kbd
Shows a key of the keyboard, so a shortcut reads as something to press and not as a word.
import { Kbd } from '@sypnia/ui/react'
A list of shortcuts
What it does on the left, the keys on the right.
- Search everything
- Ctrl K
- Run the query
- Ctrl Enter
- Save the row
- Enter
- Leave without saving
- Esc
Code
import { KeyValue, Kbd } from '@sypnia/ui/react';
export default function Shortcuts() {
return (
<KeyValue items={[
['Search everything', <span><Kbd>Ctrl</Kbd> <Kbd>K</Kbd></span>],
['Run the query', <span><Kbd>Ctrl</Kbd> <Kbd>Enter</Kbd></span>],
['Save the row', <Kbd>Enter</Kbd>],
['Leave without saving', <Kbd>Esc</Kbd>],
]} />
);
} In a sentence
Keys sit in the line of text without changing its height.
Press Tab to move to the next cell and Shift Tab to go back. Esc leaves the cell as it was.
Code
import { Kbd } from '@sypnia/ui/react';
export default function InASentence() {
return (
<p className="sy-text--sm">
Press <Kbd>Tab</Kbd> to move to the next cell and <Kbd>Shift</Kbd> <Kbd>Tab</Kbd> to go back. <Kbd>Esc</Kbd> leaves the cell as it was.
</p>
);
} When to use it
Use it when
- A shortcut is named in help text, a menu, a tooltip or a list of shortcuts.
- Instructions say which key to press: «Press Esc to cancel».
Do not use it when
- The text is code, a value or a command to type: that is machine text (
code). - The app is mostly used on phones: there is no keyboard, so do not make shortcuts the only way to do anything.
For everyone
- It is a real
kbdelement: screen readers read the key name as text. - Write key names in full («Enter», «Shift»), one key per Kbd. Symbols alone (⌘, ⇧) are not read reliably.
- A shortcut is never the only way to do something: the same action is always reachable with a button or a menu.