Skip to content

Commit

Permalink
[react-interactions] Fix focus-visible heuristic (facebook#17124)
Browse files Browse the repository at this point in the history
Respond to all keys not just `Tab`
  • Loading branch information
necolas committed Oct 17, 2019
1 parent 8facc05 commit 4fb5bf6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
7 changes: 2 additions & 5 deletions packages/react-interactions/events/src/dom/Focus.js
Expand Up @@ -151,11 +151,8 @@ function handleRootEvent(
case 'keyup': {
const nativeEvent = event.nativeEvent;
const focusTarget = state.focusTarget;
const {key, metaKey, altKey, ctrlKey} = (nativeEvent: any);
const validKey =
key === 'Enter' ||
key === ' ' ||
(key === 'Tab' && !(metaKey || (!isMac && altKey) || ctrlKey));
const {metaKey, altKey, ctrlKey} = (nativeEvent: any);
const validKey = !(metaKey || (!isMac && altKey) || ctrlKey);

if (validKey) {
state.pointerType = 'keyboard';
Expand Down
Expand Up @@ -166,7 +166,7 @@ describe.each(table)('Focus responder', hasPointerEvents => {

it('is called with the correct pointerType using a keyboard', () => {
const target = createEventTarget(ref.current);
target.keydown({key: 'Tab'});
target.keydown({key: 'LeftArrow'});
target.focus();
expect(onFocus).toHaveBeenCalledTimes(1);
expect(onFocus).toHaveBeenCalledWith(
Expand Down

0 comments on commit 4fb5bf6

Please sign in to comment.