Skip to content
HomeCobalt

Keyboard shortcuts

Gives a product's keyboard shortcuts one map that binds every key and lists them in a dialog the "?" key opens, so the keys the page answers and the keys it lists never disagree.

defineShortcuts holds the map: each shortcut's keys, its words and its group. useShortcuts binds the map's keys to handlers, useShortcut one key. ShortcutsDialog lists the map; ShortcutKeys draws one shortcut's keys in a menu row or beside a field. shortcutText and ariaKeys give the keys as text and as aria-keyshortcuts.

Examples

One map of a tool's keys: the page answers each one, and ? opens the list of them in groups, with the reader's own modifier.

Press a key from the list, or ? to see them all.

Usage

Use it when

  • A tool people use all day and learn: a research tool, an inbox, an admin table.
  • Any page that answers a key, so the key is listed and named where it is used.

Use something else when

  • A single key named beside the one action it runs. Use Kbd instead.
  • Searching for a command by name. Use CommandPalette instead.

Rules

General

Content

Avoid

Limits

Install

npx shadcn@latest add https://kaanarici.com/r/cobalt/shortcuts-dialog.json https://kaanarici.com/r/cobalt/shortcuts.json
import { ShortcutKeys, ShortcutsDialog } from "@/components/cobalt/ui/shortcuts-dialog"
import { defineShortcuts, useShortcut, useShortcuts, shortcutText, ariaKeys, type Shortcut } from "@/lib/cobalt/shortcuts"