shadcn.io is not affiliated with official shadcn/ui
Kbd examples · Pressed State
Disabled State Kbd for React
A faded Command key with a not-allowed cursor, for a shortcut that's unavailable.
Some shortcuts only work in some places: Save with nothing to save, Paste with an empty clipboard. This React example fades a single Command key with opacity-50 and shows a not-allowed cursor over it with cursor-not-allowed, plus pointer-events-auto so that cursor appears, since Kbd ignores the pointer by default.
Preview
Installation
FAQ
When should a shortcut look disabled?
When the command exists but can't run right now, and showing it helps people learn it: a menu item that's disabled, a toolbar action without a selection. If a shortcut never applies on a screen, leave it out.
Which classes make the key look disabled?
opacity-50 fades the cap to half strength, the same treatment disabled controls get across the components. cursor-not-allowed shows the not-allowed cursor, which only works with pointer-events-auto because Kbd turns pointer events off.
Should I show disabled shortcuts or hide them?
Show them when the command will become available, so the layout stays put and people learn the shortcut. Hide them when the command doesn't apply to the screen at all.
Should a disabled key be focusable?
A Kbd is never focusable. The control it belongs to decides: a disabled menu item or Button carries the disabled state, and its shortcut fades with it.
Related
- Active State KbdA ⌘K shortcut whose Command key is filled
- Hover State Kbd⌘ and K keys that change to the accent
- Command Palette Shortcut KbdThe ⌘K shortcut that opens a command
- Focus State KbdA ⌘K shortcut with a focus ring around
- Pressed Down KbdA ⌘K shortcut whose Command key sits
- Arrow Keys Cross Pattern KbdFour arrow keys in the inverted T of a