shadcn.io is not affiliated with official shadcn/ui
Keyboard Shortcuts Navbar Block for React
An app navbar whose shortcuts work: G then H, P or S moves between pages, a question mark opens a dialog with every key in a table, and each link shows its keys on hover and keyboard focus.
Installation
Overview
An app bar for React with Base UI, the chrome a task manager keeps above its pages. For Taskchord, the wordmark leads, three page links follow (Home, Projects and Settings), and a "Press ? for shortcuts" button sits at the end. The keys really work: press G, then H, P or S, and the page changes, with the bar's current-page stroke moving to it and a "G…" cap showing while the second key is awaited (for a second and a half, then it gives up). Press the question mark and a dialog lists every key in a keyboard table. Each link shows its keys as caps on hover and on keyboard focus, and while a G is waiting they show on every link; the room for them is always reserved, so nothing shifts. A document listener leaves inputs, text areas, selects, editable elements and chords with Control, Command or Alt alone, and does nothing while the dialog is open. A hidden status line announces where a key took you. On a phone there are no keys: a menu button opens a sheet from the top with the same three links. It's built from Kbd, Keyboard Table, Dialog, Sheet, Button and Guides with Lucide icons and your theme's tokens for every colour, and the bar stays one bar high (64 pixels, 56 on a phone). It is not a banner that hints at a key, nor a call to action built around one. For apps and dashboards that want the keyboard to be a first-class way to move.
FAQ
How do I add pages and keys?
Add a row to PAGES at the top of the file: a label, an icon, a value and the key that follows G. The bar, the sheet, the key handler and the dialog's table all read the list, so a new page gets its link, its caps, its sentence for screen readers and its row in the table. go(value) is the one place a page is chosen: replace its body with your router, and derive the current page from the route instead of the current state.
How does the G-then-key sequence behave?
Pressing G starts a wait of 1.5 seconds (CHORD_MS): the pending cap fades in beside the links, every link shows its caps, and a status line says "G pressed". The next key finishes it: H, P or S goes to that page, any other key cancels it. If nothing is pressed the wait times out and the cap fades away. The listener ignores Shift chords other than the question mark, so capital letters never start a sequence by accident.
Do the keys get in the way of typing?
No. The listener returns early when the keyboard is in an input, a textarea, a select or an editable element, when Control, Command or Alt is held, and while the shortcuts dialog is open. Browser and screen reader shortcuts that use those modifiers are never intercepted. The keys are single letters, so people who remap or disable them can still use the links, which are ordinary links.
How is it made accessible?
The links sit in a nav named Main, the current one marked aria-current="page". Each link points to a sentence that says how to press its keys ("Shortcut: press G, then P") through aria-describedby; the caps themselves are hidden from screen readers. The Shortcuts button says whether the dialog is open, and the dialog is a modal named Keyboard shortcuts with a keyboard table inside. Whichever way it opened, focus returns to the Shortcuts button when it closes.
The button also declares the key with aria-keyshortcuts and names the dialog it controls while it is open.
The sequence keys are not declared with aria-keyshortcuts because that attribute describes chords held together, not a sequence.
Why does the table show G then H on one cap?
The keyboard table joins keys with a plus sign, which means "held together". A sequence is not a chord, so each of the three rows passes one string, "G then H", and the table draws it as a single cap. Single keys such as the question mark and Escape are drawn as usual.
How does it work on a phone?
Below the md breakpoint the links, the caps and the Shortcuts button are gone, since there is no keyboard to press, and a menu button opens a sheet from the top whose header lines up with the bar, with the three links. Choosing one closes the sheet and Escape returns focus to the menu button. The key listener stays on at every width, so a keyboard attached to a phone or tablet still moves between pages, though no caps are shown. Nothing wraps at 320 pixels.
Related
- Pro
Command Palette Navbar
SearchA navbar for a notes app with a field-looking button and a shortcut that open a command palette: recent notes first, then pages, actions and settings in labelled groups, with the keys that work shown beside each row.
- Pro
Search Overlay Navbar
SearchA navbar for a legal-research database whose field-looking search button opens a panel from the top with a large input, recent searches you can remove, popular topic tags and live results with the matching letters marked.
- Pro
SaaS Marketing Navbar
Mega menusA one-bar marketing navbar for a product roadmap tool: a wordmark, a Product menu of four areas with icons and one-line descriptions, plain links with the current page marked, Sign in and a Shine Button, and a sheet with the same links on phones.
- Pro
Keyboard Hint Banner
Top barsA one-line shortcut hint for a text editor, aligned to the start: three shortcuts read as a sentence, each a key cap and its verb, and a link to the full list.
- Pro
Card Inset Keyboard Shortcut CTA
Code and commandsA centred card-in-card call to action built around a keyboard shortcut: three key caps in a hairline frame that press down as the keys do and open a filterable command palette, which the Shine Button opens too.
- Pro
Keyboard Shortcut Card Features
Live controlsA shortcut cheat sheet for a shortcut trainer: two groups of four shortcuts in one framed card, where pressing a shortcut while the card is focused lights its row.