Skip to content

Commit 1d1c534

Browse files
MelvinBotmkhutornyi
andcommitted
Revert "fix: restore keyboard modality on Esc/nav keys"
This reverts commit 7a7489b. Co-authored-by: mkhutornyi <mkhutornyi@users.noreply.github.com>
1 parent 0e7440b commit 1d1c534

2 files changed

Lines changed: 2 additions & 23 deletions

File tree

src/libs/hadTabNavigation.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
/** True when the user is keyboard-navigating; false when using a mouse. Tab + named nav keys set true; printable typing on body clears; printable typing inside editable fields preserves (data entry is not a modality switch). */
1+
/** True when the user is keyboard-navigating; false when typing or using a mouse. Typing/printable keys clear; Tab/Arrow/named keys preserve. */
22
let hadTabNavigation = false;
33
let teardown: (() => void) | null = null;
44

5-
// Named keys that are unambiguously keyboard navigation intent — pressing any of these should restore keyboard modality even if typing had cleared it.
6-
const KEYBOARD_NAV_KEYS = new Set(['Escape', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Home', 'End', 'PageUp', 'PageDown']);
7-
85
function setup(): void {
96
if (teardown || typeof document === 'undefined') {
107
return;
@@ -15,7 +12,7 @@ function setup(): void {
1512
if (typeof e.key !== 'string') {
1613
return;
1714
}
18-
if (e.key === 'Tab' || KEYBOARD_NAV_KEYS.has(e.key)) {
15+
if (e.key === 'Tab') {
1916
hadTabNavigation = true;
2017
return;
2118
}

tests/unit/NavigationFocusReturnTest.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -341,24 +341,6 @@ describe('captureTriggerForRoute', () => {
341341
expect(restoreTriggerForRoute('route-a')).toBe(false);
342342
});
343343

344-
it.each(['Escape', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Home', 'End', 'PageUp', 'PageDown'])(
345-
'should RESTORE modality on %s after typing — keyboard-initiated back/nav must show visible focus on the restored trigger (WCAG 2.4.7)',
346-
(navKey) => {
347-
simulateTab();
348-
simulateKey('a'); // Typing clears modality.
349-
simulateKey(navKey); // Nav key restores it.
350-
const trigger = appendButton();
351-
trigger.focus();
352-
setLastInteractiveElementForTests(trigger);
353-
354-
captureTriggerForRoute('route-a');
355-
trigger.blur();
356-
const spy = jest.spyOn(trigger, 'focus');
357-
expect(restoreTriggerForRoute('route-a')).toBe(true);
358-
expect(spy).toHaveBeenCalledWith(expect.objectContaining({focusVisible: true}));
359-
},
360-
);
361-
362344
it('should clear modality on Backspace / Delete', () => {
363345
simulateTab();
364346
simulateKey('Backspace');

0 commit comments

Comments
 (0)