Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Focus submenu button when clicked #55198

Merged
merged 12 commits into from
Oct 18, 2023
1 change: 1 addition & 0 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function block_core_navigation_add_directives_to_submenu( $w, $block_attributes
$w->set_attribute( 'data-wp-effect', 'effects.core.navigation.initMenu' );
$w->set_attribute( 'data-wp-on--focusout', 'actions.core.navigation.handleMenuFocusout' );
$w->set_attribute( 'data-wp-on--keydown', 'actions.core.navigation.handleMenuKeydown' );
$w->set_attribute( 'tabindex', '-1' );
if ( ! isset( $block_attributes['openSubmenusOnClick'] ) || false === $block_attributes['openSubmenusOnClick'] ) {
$w->set_attribute( 'data-wp-on--mouseenter', 'actions.core.navigation.openMenuOnHover' );
$w->set_attribute( 'data-wp-on--mouseleave', 'actions.core.navigation.closeMenuOnHover' );
Expand Down
5 changes: 5 additions & 0 deletions packages/block-library/src/navigation/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const openMenu = ( store, menuOpenedOn ) => {
if ( context.core.navigation.type === 'overlay' ) {
// Add a `has-modal-open` class to the <html> root.
document.documentElement.classList.add( 'has-modal-open' );
} else {
// Ensure that Safari on iOS/iPadOS trigger the mouseleave events.
document.body.setAttribute( 'tabindex', '-1' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know why this works? I'm not saying we can't do this, but I'm hesitant to do this since it could have far-reaching effects. I'd love to learn more about it as I didn't know this would trigger mouseleave events for Safari.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I don't like this. I would never set this on the <body>.

}
};

Expand All @@ -39,6 +42,8 @@ const closeMenu = ( store, menuClosedOn ) => {
context.core.navigation.previousFocus = null;
if ( context.core.navigation.type === 'overlay' ) {
document.documentElement.classList.remove( 'has-modal-open' );
} else {
document.body.removeAttribute( 'tabindex' );
}
}
};
Expand Down
Loading