Skip to content

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'

On this page
  1. A list of shortcuts
  2. In a sentence
  3. In a menu
  4. When to use it
  5. For everyone

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>
  );
}

In a menu

Press «Row»: each action shows its keys at the end of the line.

Code
import { Button, Kbd, Menu, MenuItem } from '@sypnia/ui/react';

// Press the button: each action shows the keys that do the same.
export default function InAMenu() {
  return (
    <Menu placement="bottom start" trigger={<Button iconEnd="chevron-down">Row</Button>}>
      <MenuItem icon="copy" shortcut={<><Kbd>Ctrl</Kbd> <Kbd>C</Kbd></>}>Copy row</MenuItem>
      <MenuItem icon="edit" shortcut={<Kbd>F2</Kbd>}>Edit cell</MenuItem>
      <MenuItem icon="trash" danger shortcut={<Kbd>Del</Kbd>}>Delete row</MenuItem>
    </Menu>
  );
}

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 kbd element: 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.
  1. A list of shortcuts
  2. In a sentence
  3. In a menu
  4. When to use it
  5. For everyone

    Search pages, sections and terms