@samitouri / QOS-React-2 / commits / 4fb5bf61dd

[react-interactions] Fix focus-visible heuristic (#17124)

Respond to all keys not just `Tab`

Nicolas Gallagher committed Oct 17, 2019 at 09:24 UTC 4fb5bf61dd52473330fb5b3fdf0ffc091054a28c
2 files changed +3 -6
packages/react-interactions/events/src/dom/Focus.js
+2 -5
@@ -151,11 +151,8 @@ function handleRootEvent(
151 case 'keyup': {
152 const nativeEvent = event.nativeEvent;
153 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);
156
157 if (validKey) {
158 state.pointerType = 'keyboard';
packages/react-interactions/events/src/dom/__tests__/Focus-test.internal.js
+1 -1
@@ -166,7 +166,7 @@ describe.each(table)('Focus responder', hasPointerEvents => {
166
167 it('is called with the correct pointerType using a keyboard', () => {
168 const target = createEventTarget(ref.current);
169 - target.keydown({key: 'Tab'});
169 + target.keydown({key: 'LeftArrow'});
170 target.focus();
171 expect(onFocus).toHaveBeenCalledTimes(1);
172 expect(onFocus).toHaveBeenCalledWith(