Problem/Motivation
This is a followup to #3443571-36: Mobile version of Navigation should have focus trap, but it should be released along with that issue.
keyboard focus must be trapped within it until the user:
* Selects the Close/OK/X button
* Selects the ESC key
* Clicks outside of the menu with their mouse
the close button should be reachable by keyboard same as there should be an option to close the mobile navigation by pressing the ESC key. but from my perspective if moved to a follow up those followup(s) and this issue should go into the same new version of drupal.
Setting to Major priority because #3443571: Mobile version of Navigation should have focus trap is Major.
WCAG success criteria
Steps to reproduce
- Enable the Navigation module.
- Log in as admin.
- Reduce the viewport width until the Navigation "Expand sidebar" button appears at top-left.
- Activate the "Expand sidebar" button to open the sidebar.
- If focus is not on an item within the sidebar, press the
TABkey until focus is within the sidebar. - Press the
ESCkey.
Expected behavior
- The sidebar closes.
- Focus returns to the "Expand sidebar" button.
Actual behavior
- The sidebar does not close.
- Focus remains within the sidebar.
Proposed resolution
If on the first level when pressing ESC it should close the toolbar and set focus on the "Expand sidebar" button. When hitting ESC on a popover it should keep the toolbar open but go back one level.
Remaining tasks
User interface changes
The "mobile" sidebar implements the expected behavior.
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3572628
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3572628-sidebar-close-by-escape
changes, plain diff MR !14935
Comments
Comment #2
smustgrave commentedWrong status?
Comment #3
kentr commentedYes. This started as a clone of another issue, and I neglected to change the status.
Comment #4
rkollerIn discussion with @katannshaw, @mgifford, @mherchel, and myself, we considered this follow up to the focus trap issue as a blocker in #3391723: [PLAN] Accessibility review for new Navigation bar
p.s. not sure if we should keep the focus trap issue as the parent or better move it to related issues and make the a11y meta the parent instead?
Comment #5
kentr commentedYes. I did that to tie this to the focus trap issue, but y'all made it an official higher-level blocker.
Comment #6
mherchelPostponing this on #3443571: Mobile version of Navigation should have focus trap. It'll touch the same bit of JS, and will have conflicts.
Comment #7
catch#3443571: Mobile version of Navigation should have focus trap is in.
Comment #8
smustgrave commentedSo the escape button does do something but only if you're in a popover. So should the escape key no longer close any popovers and instead close the entire toolbar?
Comment #9
mherchelWe'll work on this in the contribution room at Florida DrupalCamp 2026 in a couple days, if it still needs it.
Comment #10
smustgrave commentedTagged as the latest a11y-bugsmash "one"
Comment #11
kentr commentedHow does one see the popover?
I'm not sure that I'm interpreting the question correctly, so this may be off-base. To me,
ESCshould close the current user-opened content. So ifESCcloses the popover and returns the user to the sidebar, then anotherESCshould close the sidebar.Comment #12
smustgrave commentedSo on mobile if you open up a sub menu (in the code it calls them popovers) then esc takes you back one.
Comment #13
kentr commented@smustgrave
Ok. Thanks.
To me,
ESCshould still close the sub-menu. But then if a submenu isn't open,ESCshould close the sidebar.Comment #14
mherchelI agree with this! Look for a MR this Sunday (at the FLDC contribution sprint).
Comment #15
smustgrave commentedUpdated the summary! Thanks everyone
Comment #16
kentr commentedJust a note that this is related to closing the sub-menu / popover with
ESC: #3541741: [PP-1] Close only lowest-level submenu with Escape keyNot suggesting that it be fixed with this issue, just giving a heads up that there may be crossover in the code and some work was done on that issue in case it's useful / important here.
Comment #17
mherchelNote I was too busy mentoring at FLDC to get to this. I'm still planning on working on it this week or early next. But if someone else wants to get into it, please do so, and then I can just review :)
Comment #18
kentr commentedI'll take a stab at it.
Comment #19
kentr commentedHave made some progress, hopefully will create an MR soon.
I'm including some code to move focus to the "Expand sidebar" button when closed by
ESCdue to the following snippet from SC 2.4.11 Focus Not Obscured (Minimum) (Level AA), as well as #19 by @cwilcox808 in #3443571-19: Mobile version of Navigation should have focus trap.This also will be consistent with the behavior for the lower-level menus / sub-menus. It was in the Steps to reproduce > Expected behavior, but not in the proposed resolution.
Comment #21
kentr commentedThis is ready for review.
In my last comment, I think I conflated the snippet with the Knowbilty article that it references. The article discusses moving focus back to the navigation trigger.
For a problem that I encountered as part of the fix, I also used changes from #3541741: [PP-1] Close only lowest-level submenu with Escape key.
If those changes are accepted as part of this issue, @hinal05 should be credited here. Also, it should fix #3541741: [PP-1] Close only lowest-level submenu with Escape key.
Comment #22
lauriiiCommented on the MR
Comment #23
lauriiiThank you for addressing the feedback! Tested this again manually and this works great!
Comment #25
catchI'm not really qualified to review the js here, especially the nightwatch tests, but since @lauriii RTBCed and the approach has good consensus (and this is the last high priority navigation accessibility issue), going to go ahead here.
Committed/pushed to main and 11.x, thanks!
Comment #29
kentr commentedI think we also need to credit @hinal05. I used her code from #3541741: [PP-1] Close only lowest-level submenu with Escape key.
Unless she'll get credit on that issue? I'll check to see if it's fixed now.
Comment #30
catchI've marked that issue as outdated and applied credit over there.
Comment #31
mherchelShould this be marked as Fixed?
Comment #32
kentr commented@catch marked it as fixed in #25. Somehow it appears to have reverted.
Comment #34
kentr commentedApparently, "somehow" was me, with #29.
Also restoring the version that @catch set in #25.
Comment #35
kentr commented