From d7fdfda16237bc7a51c5ed8fb7a85c170ce3e25f Mon Sep 17 00:00:00 2001 From: Material Web Team Date: Wed, 22 Mar 2023 18:57:59 -0700 Subject: [PATCH] feat(focus): export the keydown handler PiperOrigin-RevId: 518730680 --- focus/strong-focus.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/focus/strong-focus.ts b/focus/strong-focus.ts index 12c8c33481..8bdba8479f 100644 --- a/focus/strong-focus.ts +++ b/focus/strong-focus.ts @@ -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); }