Skip to content

Commit 4fb5bf6

Browse files
authored
[react-interactions] Fix focus-visible heuristic (#17124)
Respond to all keys not just `Tab`
1 parent 8facc05 commit 4fb5bf6

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

packages/react-interactions/events/src/dom/Focus.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,8 @@ function handleRootEvent(
151151
case 'keyup': {
152152
const nativeEvent = event.nativeEvent;
153153
const focusTarget = state.focusTarget;
154-
const {key, metaKey, altKey, ctrlKey} = (nativeEvent: any);
155-
const validKey =
156-
key === 'Enter' ||
157-
key === ' ' ||
158-
(key === 'Tab' && !(metaKey || (!isMac && altKey) || ctrlKey));
154+
const {metaKey, altKey, ctrlKey} = (nativeEvent: any);
155+
const validKey = !(metaKey || (!isMac && altKey) || ctrlKey);
159156

160157
if (validKey) {
161158
state.pointerType = 'keyboard';

packages/react-interactions/events/src/dom/__tests__/Focus-test.internal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ describe.each(table)('Focus responder', hasPointerEvents => {
166166

167167
it('is called with the correct pointerType using a keyboard', () => {
168168
const target = createEventTarget(ref.current);
169-
target.keydown({key: 'Tab'});
169+
target.keydown({key: 'LeftArrow'});
170170
target.focus();
171171
expect(onFocus).toHaveBeenCalledTimes(1);
172172
expect(onFocus).toHaveBeenCalledWith(

0 commit comments

Comments
 (0)