diff --git a/packages/edit-site/src/components/navigation-sidebar/navigation-toggle/index.js b/packages/edit-site/src/components/navigation-sidebar/navigation-toggle/index.js index 0836a7f360..13d6371058 100644 --- a/packages/edit-site/src/components/navigation-sidebar/navigation-toggle/index.js +++ b/packages/edit-site/src/components/navigation-sidebar/navigation-toggle/index.js @@ -71,7 +71,10 @@ function NavigationToggle( { icon } ) { } const buttonRef = useRef(); - useResetFocusOnRouteChange( buttonRef ); + const props = { + isNavigationOpen, + }; + useResetFocusOnRouteChange( buttonRef, props ); return ( { // Don't focus for initial page load. @@ -35,6 +36,10 @@ export default function useResetFocusOnRouteChange( targetRef ) { } } + if ( isNavigationOpen ) { + return; + } + targetRef.current?.focus(); - }, [ location, targetRef, history ] ); + }, [ location, targetRef, history, isNavigationOpen ] ); }