Skip to content

Commit

Permalink
[MenuList] Fix text navigation for v4 (mui#27513)
Browse files Browse the repository at this point in the history
Fixes bug introduced by mui#19967
  • Loading branch information
ryancogswell committed Jul 30, 2021
1 parent 77a8dae commit 53be5a3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/material-ui/src/MenuList/MenuList.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function moveFocus(
// Prevent infinite loop.
if (nextFocus === list.firstChild) {
if (wrappedOnce) {
return;
return false;
}
wrappedOnce = true;
}
Expand All @@ -80,9 +80,10 @@ function moveFocus(
nextFocus = traversalFunction(list, nextFocus, disableListWrap);
} else {
nextFocus.focus();
return;
return true;
}
}
return false;
}

const useEnhancedEffect = typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect;
Expand Down
3 changes: 2 additions & 1 deletion packages/material-ui/test/integration/MenuList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,13 +519,14 @@ describe('<MenuList> integration', () => {
it('matches rapidly typed text', () => {
render(
<MenuList autoFocus>
<MenuItem>War</MenuItem>
<MenuItem>Worm</MenuItem>
<MenuItem>Ordinary</MenuItem>
</MenuList>,
);

fireEvent.keyDown(screen.getByRole('menu'), { key: 'W' });
fireEvent.keyDown(screen.getByText('Worm'), { key: 'o' });
fireEvent.keyDown(screen.getByText('War'), { key: 'o' });

expect(screen.getByText('Worm')).toHaveFocus();
});
Expand Down

0 comments on commit 53be5a3

Please sign in to comment.