From 53be5a3b10cdc83a92d1c2a39c5cae4500c4dd52 Mon Sep 17 00:00:00 2001 From: Ryan Cogswell <287804+ryancogswell@users.noreply.github.com> Date: Fri, 30 Jul 2021 15:07:48 -0500 Subject: [PATCH] [MenuList] Fix text navigation for v4 (#27513) Fixes bug introduced by #19967 --- packages/material-ui/src/MenuList/MenuList.js | 5 +++-- packages/material-ui/test/integration/MenuList.test.js | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/material-ui/src/MenuList/MenuList.js b/packages/material-ui/src/MenuList/MenuList.js index 5ce5ba555b78cd..2679039ee335b6 100644 --- a/packages/material-ui/src/MenuList/MenuList.js +++ b/packages/material-ui/src/MenuList/MenuList.js @@ -61,7 +61,7 @@ function moveFocus( // Prevent infinite loop. if (nextFocus === list.firstChild) { if (wrappedOnce) { - return; + return false; } wrappedOnce = true; } @@ -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; diff --git a/packages/material-ui/test/integration/MenuList.test.js b/packages/material-ui/test/integration/MenuList.test.js index 08560b8fab1a8d..56f9cd9152b5d0 100644 --- a/packages/material-ui/test/integration/MenuList.test.js +++ b/packages/material-ui/test/integration/MenuList.test.js @@ -519,13 +519,14 @@ describe(' integration', () => { it('matches rapidly typed text', () => { render( + War Worm Ordinary , ); 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(); });