Skip to content

Commit

Permalink
Editor: when Toggle navigation receives state false, focus (#37265)
Browse files Browse the repository at this point in the history
* Site Editor: when Toggle navigation receives state false, focus the trigger for screen readers.

* Add comment that points to a future PR

Co-authored-by: George Mamadashvili <georgemamadashvili@gmail.com>

Co-authored-by: George Mamadashvili <georgemamadashvili@gmail.com>
  • Loading branch information
alexstine and Mamaduka committed Dec 17, 2021
1 parent 00bf8f6 commit 8b2b37e
Showing 1 changed file with 12 additions and 0 deletions.
Expand Up @@ -2,6 +2,7 @@
* WordPress dependencies
*/
import { useSelect, useDispatch } from '@wordpress/data';
import { useEffect, useRef } from '@wordpress/element';
import {
Button,
Icon,
Expand Down Expand Up @@ -40,6 +41,16 @@ function NavigationToggle( { icon } ) {

const disableMotion = useReducedMotion();

const navigationToggleRef = useRef();

useEffect( () => {
// TODO: Remove this effect when alternative solution is merged.
// See: https://github.com/WordPress/gutenberg/pull/37314
if ( ! isNavigationOpen ) {
navigationToggleRef.current.focus();
}
}, [ isNavigationOpen ] );

const toggleNavigationPanel = () =>
setIsNavigationPanelOpened( ! isNavigationOpen );

Expand Down Expand Up @@ -79,6 +90,7 @@ function NavigationToggle( { icon } ) {
<Button
className="edit-site-navigation-toggle__button has-icon"
label={ __( 'Toggle navigation' ) }
ref={ navigationToggleRef }
// isPressed will add unwanted styles.
aria-pressed={ isNavigationOpen }
onClick={ toggleNavigationPanel }
Expand Down

0 comments on commit 8b2b37e

Please sign in to comment.