Skip to content

KeyboardShortcutsHelp

MD · 1950B gzip budget

A shortcut reference dialog inheriting the focus trap every overlay gets.

Category
Navigation
Budget
md, several states or a live subscription
External runtime
React / React DOM only
axe fixtureSSR rendersource scanbundle budget

Preview

Live fixture
Preview locale

Try the component here. Locale-aware formatting and direction follow the selected language; example content and labels are not automatically translated. Overlay demos use interactive launchers.

Install

npx shadcn@latest add https://gear5-ui.vercel.app/r/keyboard-shortcuts-help.json

Copies the source into your project. Pulls in 8 shared registry items: dialog, use-focus-trap, cn, use-locale, locale, portal, use-hydrated, kbd.

New here? Set up Tailwind and import aliases first →

Source & props

Edit on GitHub ↗

Prop types and inline documentation are included below. This is repository source; the installer rewrites shared imports for your project.

import { Dialog } from "./dialog";
import { Kbd } from "./kbd";

export interface Shortcut {
  keys: string[];
  description: string;
}

export interface KeyboardShortcutsHelpProps {
  open: boolean;
  onClose: () => void;
  shortcuts: Shortcut[];
  title?: string;
}

/**
 * A shortcut reference, built on `Dialog` so it inherits the focus trap and
 * Escape-to-close every other overlay in the library has — a "just show a
 * list of shortcuts" dialog is exactly the kind of secondary UI that skips
 * this in most apps and traps keyboard users when it does.
 */
export function KeyboardShortcutsHelp({ open, onClose, shortcuts, title = "Keyboard shortcuts" }: KeyboardShortcutsHelpProps) {
  return (
    <Dialog open={open} onClose={onClose} title={title}>
      <ul className="flex flex-col gap-2">
        {shortcuts.map((shortcut) => (
          <li key={shortcut.description} className="flex items-center justify-between gap-4 text-sm">
            <span>{shortcut.description}</span>
            <span className="flex gap-1">
              {shortcut.keys.map((key) => (
                <Kbd key={key}>{key}</Kbd>
              ))}
            </span>
          </li>
        ))}
      </ul>
    </Dialog>
  );
}

What CI checks

Quality contract
  • Bundled, minified and gzipped against its tier budget
  • Audited by axe in the state previewed above
  • Rendered through react-dom/server with no browser globals
  • Scanned for network calls, dangerous sinks, and unguarded animation