Add a registry model and view for managing keyboard shortcuts.
Review Request #13591 — Created Feb. 29, 2024 and submitted
Part of Ink's focus on accessibility is formalizing support for keyboard
shortcuts. Components will be able to easily list keyboard shortcuts
that trigger an element, providing both a visual indicator and ARIA
information for screen readers.Keyboard shortcuts will be registered in the new
KeyboardShortcutRegistry
model, which takes a key, modifier flags, and
a callback handler, and registers it for quick access.A corresponding
KeyboardShortcutRegistryView
can be attached to an
existing element and a registry model to invoke the handlers when those
keys are pressed.Once attached, a registry view can be found on any ancestor DOM element
by usingKeyboardShortcutRegistryView.findNearestRegistryView
.
Similarly, a nearest registry can be found using
findNearestRegistry().
. This makes it easy for components to
automatically register with the correct registry.The plan is to eventually let the view pop up a dialog when
?
is
pressed, to show the available keyboard shortcuts. This has been a
long-standing plan for Review Board, and with these new foundational
classes, we'll be able to offer this.
Unit tests pass.
Summary | ID |
---|---|
16876d6e49792e51376bd3cae1018b96bb70789d |
Description | From | Last Updated |
---|---|---|
Typo: "mappin" -> "mapping". |
maubin |
- Change Summary:
-
- Added automatic association between elements and a registry, and functions for finding the nearest registry/view from a starting element.
registerShortcut()
now returns the registration information, for later unregistering.- Renamed the interfaces to consistently use
KeyboardShortcut
in the name. - Fixed a typo in docs.
- Description:
-
Part of Ink's focus on accessibility is formalizing support for keyboard
shortcuts. Components will be able to easily list keyboard shortcuts that trigger an element, providing both a visual indicator and ARIA information for screen readers. Keyboard shortcuts will be registered in the new
KeyboardShortcutRegistry
model, which takes a key, modifier flags, anda callback handler, and registers it for quick access. A corresponding
KeyboardShortcutRegistryView
can be attached to anexisting element and a registry model to invoke the handlers when those keys are pressed. + Once attached, a registry view can be found on any ancestor DOM element
+ by using KeyboardShortcutRegistryView.findNearestRegistryView
.+ Similarly, a nearest registry can be found using + findNearestRegistry().
. This makes it easy for components to+ automatically register with the correct registry. + The plan is to eventually let the view pop up a dialog when
?
ispressed, to show the available keyboard shortcuts. This has been a long-standing plan for Review Board, and with these new foundational classes, we'll be able to offer this. - Commits:
-
Summary ID 487ca4c8562f412b6d5b0219e07417b24321987c c51c376defc0f4b148e83b7c83db42fcb8248676 - Diff:
-
Revision 2 (+2588)
Checks run (2 succeeded)
- Change Summary:
-
- Fixed map key generation to normalize the shortcut key to lowercase, to avoid mismatches between registration and events.
- Updated the call to get a shortcut to pass in an explicit modifiers object, instead of just casting the event.
- Commits:
-
Summary ID c51c376defc0f4b148e83b7c83db42fcb8248676 16876d6e49792e51376bd3cae1018b96bb70789d - Diff:
-
Revision 3 (+2598)