Skip to Content
Cristal

Content

Keyboard key

A key or keyboard shortcut in running text.

<cr-kbd>CrKbd

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 , then confirm with Enter.

Undo the last action: ; redo it: .

'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 kbd element, and a shortcut is a kbd grouping 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

PropertyTypeDefaultDescription
keysstring—Raccourci, touches séparées par + : « Mod+K », « Shift+Alt+P ». Mod, Ctrl, Alt et Shift s'adaptent au système.

Slots

SlotDescription
defaultUne touche, quand keys n'est pas donné.

CSS parts

To style it from outside: cr-kbd::part(name) { … }

PartDescription
keyChaque touche.

On this page