Skip to content

Commit 4619ea5

Browse files
dfreedmcopybara-github
authored andcommitted
chore(focus): Listen to KeyboardEvent.key instead of .code
PiperOrigin-RevId: 404053797
1 parent 34983a2 commit 4619ea5

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

components/focus/strong-focus.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ let focusObject: StrongFocus = new FocusGlobal();
2525
/**
2626
* Set of keyboard event codes that correspond to keyboard navigation
2727
*/
28-
const KEYBOARD_NAVIGATION_CODES =
28+
const KEYBOARD_NAVIGATION_KEYS =
2929
new Set(['Tab', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown']);
3030

3131
const KEYDOWN_HANDLER = (e: KeyboardEvent) => {
32-
if (KEYBOARD_NAVIGATION_CODES.has(e.code)) {
32+
if (KEYBOARD_NAVIGATION_KEYS.has(e.key)) {
3333
focusObject.setVisible(true);
3434
}
3535
};

components/focus/test/strong-focus.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class MockFocus {
1515
}
1616
}
1717

18-
function simulateKeydown(code: string) {
19-
const ev = new KeyboardEvent('keydown', {code, bubbles: true});
18+
function simulateKeydown(key: string) {
19+
const ev = new KeyboardEvent('keydown', {key, bubbles: true});
2020
window.dispatchEvent(ev);
2121
}
2222

0 commit comments

Comments
 (0)