Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Keyboard Shortcuts Settings Block for React

A keyboard shortcuts editor: twelve editor actions in three groups with their keys in Kbd caps, a Change button that records the next combination, a conflict check with Replace or Cancel, Changed marks and Reset, a search and a PC or Mac choice for the key words.

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

Let people bind their own keys and be told when two actions want the same ones, with this keyboard shortcuts editor for React with Base UI. A hairline frame with a plus mark on each corner opens with a toolbar: a search over action names and keys, a Segment Group that shows the keys as PC or Mac words, and a Reset all Button. Under it a table, in a frame that keeps its height while it scrolls, lists twelve editor actions in Navigation, Editing and View, each with its keys in Kbd caps and a Change button. Change records the next combination you press (Escape cancels), and if another action already has it the row asks "Already used by Go to file. Replace or Cancel." Rows that differ from the default carry a Changed mark and a Reset. The last band counts unsaved changes beside a Shine Button to save them and an outline Button to discard them. On a phone each action is a card. It's built from Kbd, Segment Group, Input, Button, Shine Button, Empty and Guides, with a CSS entrance only. For a code editor, a design tool, a mail client or any product with commands.

FAQ

How does recording a combination work?

Press Change on a row, then the keys. While a row records, the panel hears every key pressed inside it, through a listener on the panel itself that is removed as soon as recording stops, so nothing is bound on the page. Escape cancels and returns focus to Change; Tab, or clicking away, stops recording and moves on. A bare letter is refused with a reason, because it would stop you typing; a combination needs Ctrl, Cmd or Alt, except the keys F1 to F12. Some combinations are taken by the browser or the system before the page sees them (closing a tab, for one), so they cannot be recorded.

What happens when a combination is already taken?

The row says which action has it and shows Replace and Cancel in place of Change and Reset, with focus on Replace. Replace gives the combination to this action and leaves the other one not set, and the status line says so; Cancel keeps what the row had. Reset on a row whose default was taken meanwhile asks the same question. Reset all restores every default at once, and the defaults are all different, so it never conflicts.

Why are PC and Mac a choice, and not detected?

Because what a person types and what they read are different jobs. Ctrl and Cmd both record as Mod, and the PC or Mac choice only decides the words printed on the caps: Mod as Ctrl or Cmd, Alt as Alt or Option. A shared account, a remote machine or a keyboard from another system can all differ from what a browser reports, so the choice is theirs. Store combinations as mod+shift+P strings and print them the same way.

How do I use my own actions, and what stays local?

Edit ACTIONS: each has an id, a group, a name and its default combination. SAVED holds what the account has stored when the page opens. Nothing leaves the page: Save keeps the edited copy as the saved one and says so in this demo, Discard puts the saved copy back, and the status line counts how many differ. To make it real, send the changed combinations to your API in the save handler and read them where you bind the keys. Save and Discard are marked aria-disabled rather than disabled while nothing changed, so they keep their place and focus.

Is it accessible, and how does it look on a phone?

It is a native table with a caption, column headers and the action as each row's header. Each Change button is named for its action and is marked pressed while it records; the keys are read out as one phrase ("Ctrl plus Shift plus P") while the caps are decorative; and the status line is a polite live region that is present from the start. Below the medium breakpoint each action is a card: its name and Changed mark, its keys, then the two buttons side by side.

  • Pro

    A markdown notes app with its keyboard shortcuts sheet shown open: 16 shortcuts in three columns drawn as keycaps, a Mac and Windows switch that rewrites the caps, a search, and a key tester that names any chord you press.

  • Pro

    A task app's shortcut sheet as a command menu shown open as a help popover at the corner: a Mac or Windows switch re-labels every key cap, groups fold from their heads, search filters by action name, and a button really copies the list as a Markdown table.

  • Pro

    A code review tool's shortcut sheet you can practise on: a table of six shortcuts that tick off as you press them while focus is inside the panel, a chord with a waiting state, and a Command or Ctrl switch.

  • Pro

    Language and Region Settings

    Appearance and locale

    A language and region settings panel: two selects over three cells that show what they do, a sort order made by the language's collation, a month marked with the region's first weekday, and units with a worked example.

  • Pro

    A notification settings panel: a channel strip with all-or-nothing checkboxes, a matrix of switches by activity and channel with a locked security email, quiet hours, and a save bar that counts unsaved changes.

  • Pro

    Appearance Settings

    Appearance and locale

    An appearance settings panel that previews instead of applying: a drawn app window that wears the choices, theme and contrast cards with a drawn thumbnail each, a text-size slider with a sample sentence and a reduce motion switch with a replay.