KeybindingHint Indicates the presence of a keybinding available for an action.
DraftNot reviewed for accessibility Use KeybindingHint
to make keyboard shortcuts discoverable. Can render visual keybinding hints in condensed (abbreviated) form or expanded form, and provides accessible alternative text for screen reader users.
Move down control ⌃ down arrow ↓
Delete shift ⇧ control ⌃ delete Del
import { KeybindingHint } from '@primer/react/drafts'
Use the full names of the keys as returned by KeyboardEvent.key
. Key names are case-insensitive.
render (
< >
< KeybindingHint keys = " a " /> < br />
< KeybindingHint keys = " B " /> < br />
< KeybindingHint keys = " ArrowLeft " /> < br />
< KeybindingHint keys = " shift " />
</ > ,
)
ReferenceError: KeybindingHint is not defined Because the +
and space characters are used to build chords and sequences as described below, their names must be spelled out to be used as keys.
render (
< >
< KeybindingHint keys = " Plus " /> < br />
< KeybindingHint keys = " Space " />
</ > ,
)
ReferenceError: KeybindingHint is not defined Chords are multiple keys that are pressed at the same time. Combine keys in a chord with +
. Keys are automatically sorted into a standardized order so that modifiers come first.
render (
< >
< KeybindingHint keys = " Alt+a " /> < br />
< KeybindingHint keys = " a+Alt " /> < br />
< KeybindingHint keys = " Control+Shift+ArrowUp " /> < br />
< KeybindingHint keys = " Meta+Shift+& " />
</ > ,
)
ReferenceError: KeybindingHint is not defined Typical chords use Command
on MacOS and Control
on other devices. To automatically render Command
or Control
based on the user's operating system, use the special key name Mod
.
render ( < KeybindingHint keys = " Mod+Shift+X " /> )
ReferenceError: KeybindingHint is not defined Sequences are keys or chords that are pressed one after the other. Combine elements in a sequence with a space. For example, a b
means "press a, then press b".
render (
< >
< KeybindingHint keys = " a b " /> < br />
< KeybindingHint keys = " Mod+g ArrowLeft " />
</ > ,
)
ReferenceError: KeybindingHint is not defined The default condensed
format should be used on UI elements like buttons, menuitems, and inputs. In long-form text (prose), the full
variant can be used instead to help the text flow better.
render (
< Text >
Press < KeybindingHint keys = " Mod+Enter " format = " ful " /> to submit the form.
</ Text > ,
)
ReferenceError: KeybindingHint is not defined When rendering on 'emphasis' colors, use the onEmphasis
variant.
const CmdEnterHint = ( ) => < KeybindingHint variant = " onEmphasis " keys = " Mod+Enter " />
render (
< Button variant = " primary " trailingVisual = { CmdEnterHint } >
Submit
</ Button > ,
)
ReferenceError: KeybindingHint is not defined Name Type Default Description keys string The keys involved in this keybinding.
format 'condensed' | 'full' 'condensed' Control the display format.
variant 'normal' | 'onEmphasis' 'normal' Set to onEmphasis
for display on 'emphasis' colors.
Component props and basic example usage of the component are documented on primer.style/react . Component does not have any unnecessary third-party dependencies. Component can adapt to different themes. Component can adapt to different screen sizes. Component has robust unit test coverage (100% where achievable). Component has visual regression coverage of its default and interactive states. Component does not introduce any axe violations. Component has been manually reviewed by the accessibility team and any resulting issues have been addressed. Component is used in a production application. Common usage examples are documented on primer.style/react . Common usage examples are documented in storybook stories. Component has been reviewed by a systems designer and any resulting issues have been addressed. Component does not introduce any performance regressions. Component API has been stable with no breaking changes for at least one month. Feedback on API usability has been sought from developers using the component and any resulting issues have been addressed. Component has corresponding design guidelines documented in the interface guidelines . Component has corresponding Figma component in the Primer Web library. Tooling (such as linters, codemods, etc.) exists to prevent further use of alternatives.