Skip to content

Hotkey

A keyboard shortcut shown the way this person will press it (⌘ on Apple keyboards, Ctrl elsewhere), and listened to when it has an action.

import { Hotkey } from '@sypnia/ui/react'

On this page
  1. Shortcuts
  2. When to use it
  3. For everyone
  4. Props

Shortcuts

Search CtrlK

Command palette CtrlShiftP

Toggle the panel CtrlJ pressed 0 times

Code
import { useState } from 'react';
import { Hotkey } from '@sypnia/ui/react';

// ⌘ on Apple keyboards, Ctrl elsewhere. Press Ctrl/⌘ + J here.
export default function Keys() {
  const [n, setN] = useState(0);
  return (
    <div className="sy-stack" style={{ '--gap': 'var(--s-2)' } as React.CSSProperties}>
      <p className="sy-row">Search <Hotkey keys="mod+k" label="Search" /></p>
      <p className="sy-row">Command palette <Hotkey keys="mod+shift+p" label="Command palette" /></p>
      <p className="sy-row">Toggle the panel <Hotkey keys="mod+j" label="Toggle the panel" onPress={() => setN((x) => x + 1)} /> <span className="sy-text--muted sy-text--sm">pressed {n} times</span></p>
    </div>
  );
}

When to use it

Use it when

  • Menus and lists of shortcuts; actions people repeat all day.

Do not use it when

  • A shortcut as the only way to do something.

For everyone

  • It is named with its action and keys; it does not fire while the person types in a field (except with ⌘/Ctrl).

Props

HotkeyTypeDefault
keysrequired string
label string
onPress (() => void)
  1. Shortcuts
  2. When to use it
  3. For everyone
  4. Props

    Search pages, sections and terms