Skip to content

Navigation: close hover-opened submenus on Escape key press - #78379

Open
Gilmoursa wants to merge 2 commits into
WordPress:trunkfrom
Gilmoursa:fix/78355-submenu-escape-hover
Open

Gilmoursa wants to merge 2 commits into
WordPress:trunkfrom
Gilmoursa:fix/78355-submenu-escape-hover

Conversation

@Gilmoursa

Copy link
Copy Markdown

Closes #78355

What?

Move the Escape key handler in handleMenuKeydown outside of the menuOpenedBy.click conditional, and also call closeMenu( 'hover' ), so that hover-opened submenus are dismissed when the user presses Escape.

Why?

The Escape branch in handleMenuKeydown was gated on state.menuOpenedBy.click. When a submenu was opened via pointer hover, menuOpenedBy.hover was set but menuOpenedBy.click was not, so the Escape key did nothing.

This violates WCAG 1.4.13 — Content on Hover or Focus, which requires that content triggered by hover can be dismissed without moving the pointer or keyboard focus.

How?

In packages/block-library/src/navigation/view.js, the handleMenuKeydown action previously looked like:

if ( state.menuOpenedBy.click ) {
    if ( event.key === 'Escape' ) {
        actions.closeMenu( 'click' );
        actions.closeMenu( 'focus' );
        return;
    }
    // Tab focus trap ...
}

The Escape check is moved before the click gate and extended to also close the hover state:

if ( event.key === 'Escape' ) {
    actions.closeMenu( 'click' );
    actions.closeMenu( 'hover' );
    actions.closeMenu( 'focus' );
    return;
}
if ( state.menuOpenedBy.click ) {
    // Tab focus trap (unchanged) ...
}

The Tab focus-trap logic remains gated on menuOpenedBy.click since it only applies to the click-opened overlay menu.

Testing Instructions

  1. Set up a Navigation block with at least one item that has a submenu (child links).
  2. In the Navigation block settings, set Submenus → Show on hover.
  3. Visit the front end of the site.
  4. Hover over the parent navigation item — the submenu should open.
  5. Press the Escape key — the submenu should close without moving the mouse.
  6. Also verify that clicking to open the submenu (if available) and pressing Escape still closes it correctly.

Testing Instructions for Keyboard

  1. Tab to the Navigation block on the front end.
  2. Tab to a parent navigation link that has a submenu configured to open on hover.
  3. Hover the mouse over the same item to trigger the hover-open while keyboard focus is on the link.
  4. Press Escape — the submenu should close.
  5. Verify keyboard focus remains on the trigger link (it should not move).
  6. Tab through the navigation normally to confirm no regressions in keyboard behavior.

Screenshots or screencast

This fix affects hover-dismiss behavior on the front end. No editor UI change.

Use of AI Tools

This pull request was developed with assistance from Claude (Anthropic). Claude identified the root cause, implemented the fix, and verified it against the existing test suite. The change was reviewed before submission per the WordPress AI Guidelines.

Fixes WordPress#78355

The Escape key handler in handleMenuKeydown was gated on
menuOpenedBy.click, so submenus opened via pointer hover could not be
dismissed with Escape. This violates WCAG 1.4.13 (Content on Hover or
Focus), which requires that hover-triggered content can be dismissed
without moving the pointer.

Move the Escape branch outside the click conditional and also call
closeMenu( 'hover' ), so the key closes the submenu regardless of how
it was opened.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label May 17, 2026
@github-actions

github-actions Bot commented May 17, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Gilmoursa <gilmoursa@git.wordpress.org>
Co-authored-by: joedolson <joedolson@git.wordpress.org>
Co-authored-by: xucindyy <xucindyy@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions Bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label May 17, 2026
@github-actions

Copy link
Copy Markdown

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @Gilmoursa! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Block library /packages/block-library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Navigation submenu does not dismiss on Escape key press when opened via hover

2 participants