Skip to content

Commit

Permalink
feat(focus): export the keydown handler
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 518730680
  • Loading branch information
material-web-copybara authored and copybara-github committed Mar 23, 2023
1 parent 85232d5 commit d7fdfda
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion focus/strong-focus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ let focusObject: StrongFocus = new FocusGlobal();
const KEYBOARD_NAVIGATION_KEYS =
new Set(['Tab', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown']);

function keydownHandler(e: KeyboardEvent) {
/**
* Components should call this when a user interacts with a component with a
* keyboard event in the very special case that the component needs to call
* focus inside of a keydown handler. Otherwise, this module will handle
* keyboard events on window.
*
* By default, this will enable the strong focus to be shown.
*
* @param e The native keyboard event.
*/
export function keydownHandler(e: KeyboardEvent) {
if (KEYBOARD_NAVIGATION_KEYS.has(e.key)) {
focusObject.setVisible(true);
}
Expand Down

0 comments on commit d7fdfda

Please sign in to comment.