Repository navigation
Format a hotkey for aria-keyshortcuts
#275
sss-Mihail-sss
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
The problem
A control that has a shortcut should announce it to screen readers with
aria-keyshortcuts. Today the hotkey is written once foruseHotkeyand a second time by hand for the attribute:The two drift apart when the default changes, and the attribute never follows a user's custom hotkey (
useCustomHotkeys).formatForDisplaydoesn't fit: it gives symbols for people (⌘K), and ARIA wants the spec's modifier names andKeyboardEvent.keyvalues (Meta+K).Proposal
A formatter next to
formatForDisplay:ModbecomesMetaon macOS andControlelsewhere. Without a platform (on a server, or in a static shell that doesn't know the user's OS) it gives both alternatives,Control+K Meta+K, so the attribute is correct for everyone and hydrates the same.Control,Alt,Shift,Meta; keys asKeyboardEvent.keyvalues (/,Escape,ArrowUp), withSpacefor the space bar.formatForAria(['Mod+K', '/'])→Control+K Meta+K /.['G', 'H']) has no ARIA form; it is left out, andundefinedwhen nothing is left, so the attribute isn't rendered.And in the React adapter, for app hotkeys, a hook that follows custom hotkeys:
It would read the effective hotkey (the user's custom one or the default) and the provider's
platform, likeuseFormatForDisplay.What we do now
A small helper in the app that replaces
Mod+with bothControl+andMeta+and drops sequences. It works for our three shortcuts, but it doesn't know custom hotkeys or key-name details, which the library already parses.Happy to send a PR if the shape looks right.
All reactions