soft
Hotkeys
A keyboard shortcut, displayed. It renders as nested <kbd> elements, spells its glyphs per platform, and can listen for the combination it shows if you ask it to.
Usage
Examples
What you can write
keys is a plain string, +-separated, where neither case nor spaces matter. mod is the modifier that belongs to the system, Command on a Mac and Ctrl everywhere else, where meta names that physical key literally. A token the design system does not know is drawn exactly as it was written, and the + key is written plus.
| You write | macOS | Windows and Linux |
|---|---|---|
mod | Keyboard shortcut: Command | Keyboard shortcut: Ctrl |
metacmdcommandwinsuper | Keyboard shortcut: Command | Keyboard shortcut: Win |
ctrlcontrol | Keyboard shortcut: Ctrl | Keyboard shortcut: Ctrl |
altoptionopt | Keyboard shortcut: Alt | Keyboard shortcut: Alt |
shift | Keyboard shortcut: Shift | Keyboard shortcut: Shift |
enterreturn | Keyboard shortcut: Enter | Keyboard shortcut: Enter |
escescape | Keyboard shortcut: Esc | Keyboard shortcut: Esc |
space | Keyboard shortcut: Space | Keyboard shortcut: Space |
backspace | Keyboard shortcut: Backspace | Keyboard shortcut: Backspace |
deletedel | Keyboard shortcut: Del | Keyboard shortcut: Del |
tab | Keyboard shortcut: Tab | Keyboard shortcut: Tab |
updownleftright | Keyboard shortcut: Up arrowKeyboard shortcut: Down arrowKeyboard shortcut: Left arrowKeyboard shortcut: Right arrow | Keyboard shortcut: Up arrowKeyboard shortcut: Down arrowKeyboard shortcut: Left arrowKeyboard shortcut: Right arrow |
plus | Keyboard shortcut: + | Keyboard shortcut: + |
kf5, | Keyboard shortcut: KKeyboard shortcut: F5Keyboard shortcut: , | Keyboard shortcut: KKeyboard shortcut: F5Keyboard shortcut: , |
Variants
variant draws the caps tinted, outlined or raised. There is no tone and no colour prop: every paint derives from the colour the component inherits.
outline
elevated
Sizes
size takes xs or sm, and compact takes 4px off either of them. A cap holding a single character is square.
xs
sm
xs compact
sm compact
Attached
attached moves the decoration from each cap to the shortcut as a whole, so the combination reads as one key. It is purely visual: the markup, the caps and the announced name are identical either way.
One cap per key
attached
attached, no separator
Platform
platform forces the system instead of reading it once the component is in the page, which is what a table showing every system needs.
macOS
Windows
Linux
Unknown
Separator
separator is what is written between two caps, + by default. An empty string leaves the gap in place and gives the macOS convention.
The default
Keyboard shortcut: Ctrl + Shift + KNothing, the macOS convention
Keyboard shortcut: Ctrl + Shift + KA middle dot
Keyboard shortcut: Ctrl + Shift + KA slash
In text and in components
A cap takes its size from the size scale, xs by default, and sits on the middle of the line around it. Its usual homes are the end of a menu row, a tooltip, and the control the shortcut is a second route to.
Press Keyboard shortcut: Ctrl + K to open the command palette, then type the first letters of what you are after. Keyboard shortcut: Esc puts it away again.
Listening
listen makes the component watch for the combination it shows and emit trigger. Modifiers are matched exactly, so mod+k and mod+shift+k can both exist. allowDefault keeps the browser binding, and allowInInput lets the shortcut fire while the reader is typing in a field. Escape is reported but never cancelled, so it still closes dialogs. Matching reads the character the key produced: a symbol typed with Shift (?), a digit on an AZERTY layout and an Option + letter on macOS do not match, so prefer letters and named keys.
Keyboard shortcut: Ctrl + KPress it anywhere on the page. Fired 0 times.
Keyboard shortcut: Ctrl + S With allowDefault, the browser still saves the page. Fired 0 times.
Keyboard shortcut: Ctrl + JQuiet while a field has the focus: 0
Keyboard shortcut: Ctrl + JWith allowInInput, it fires there too: 0
API
Props
| Prop | Type | Default |
|---|---|---|
keys | string | none |
The combination, separated by +: mod+k, ctrl+shift+p, alt+enter. Case and spaces do not matter. mod is the cross-platform modifier, Command on macOS and Ctrl everywhere else, while meta is the literal Command or Windows key. An unknown token is displayed as it was declared, and the + key itself is written plus. | ||
variant | HotkeysVariant'soft' | 'outline' | 'elevated' | 'soft' |
| How a key cap is drawn: tinted, outlined, or raised off the page. | ||
attached | boolean | false |
| Draws the whole combination as a single key rather than as several, which puts the separator inside the key instead of between two of them. It is purely visual: the markup and the announced name are identical either way. | ||
size | HotkeysSize'xs' | 'sm' | 'xs' |
| The size of the caps. A shortcut is chrome beside other text, so it starts at the smallest. | ||
compact | boolean | false |
| Takes 4px off the height, leaving the padding and the text as they are. | ||
platform | HotkeysPlatform'mac' | 'windows' | 'linux' | 'other' | none |
| Forces the keyboard's operating system instead of detecting it, for a deterministic rendering or a host that already knows. | ||
separator | string | '+' |
| What is written between two caps. An empty string gives the macOS convention, where the symbols simply follow one another. | ||
listen | boolean | false |
| Actually listens for the combination and reports it. It is off by default: a component whose job is to display a shortcut must not capture the page's keyboard without being asked. | ||
allowDefault | boolean | false |
| While listening, lets the browser go on doing whatever the combination normally does. Left out, the browser is stopped, which is the entire point of taking a combination over. Escape is never stopped: it has to stay the close request of dialogs. | ||
allowInInput | boolean | false |
| While listening, fires even when the reader is typing in a field. It is off by default, so a shortcut cannot fire in the middle of a sentence. | ||
label | string | none |
| What screen readers announce. It falls back to the design system dictionary, which spells the modifiers as words: the glyph wins on screen, the word wins in the accessible name. | ||
Events
| Event | Type |
|---|---|
trigger | [event: KeyboardEvent] |
The combination was pressed, with the original keyboard event. It only fires while listen is set. | |