Fix: Escape key dismisses hover-opened submenus (WCAG 2.1 SC 1.4.13)#968
Open
Contributolo wants to merge 2 commits intostellarwp:masterfrom
Open
Fix: Escape key dismisses hover-opened submenus (WCAG 2.1 SC 1.4.13)#968Contributolo wants to merge 2 commits intostellarwp:masterfrom
Contributolo wants to merge 2 commits intostellarwp:masterfrom
Conversation
Add functionality to dismiss hover-opened submenus with Escape key.
Add styles for submenu dismissal on Escape key press.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Navigation (Adv) Block already handles
Escapefor submenus opened via toggle button click (keyCode === 27inkb-navigation-block.js). However, submenus opened via CSS:hovercannot be dismissed withEscape.The CSS rule responsible:
Since
:hoveris a CSS pseudo-class that cannot be removed via JavaScript, pressingEscapewhile hovering a submenu has no effect.This violates:
Since June 2025, the European Accessibility Act (EAA) makes WCAG 2.1 AA compliance a legal requirement for commercial websites in the EU.
Solution
.menu-item-has-childrenelements viamouseenter/mouseleave.keydownlistener forEscapethat adds akb-nav-esc-closeclass to the deepest hovered menu item..menu-item.kb-nav-esc-close > ul.sub-menu { display: none !important }overrides the:hovervisibility. The!importantis necessary because CSS:hovercannot be programmatically disabled.mouseenter(re-hover) ormouseleave(pointer exits), restoring normal behavior.Escapehandler for toggle-opened submenus (keyboard focus inside submenu) is unchanged; the new global handler skips if focus is already inside asub-menu.Changes
src/assets/js/kb-navigation-block.js: AddedhoveredItemstracking,initHoverEscDismiss(), andhandleHoverEscDismiss().src/blocks/navigation/style.scss: Added.kb-nav-esc-closeoverride rule.Testing
Escape-- submenu closes. Move pointer away and back -- submenu reopens normally.Escape-- submenu closes, focus returns to toggle button (existing behavior, unchanged).Escape-- only the deepest submenu closes.