More reliably close the menu when focus moves away from the last item#417
Open
More reliably close the menu when focus moves away from the last item#417
Conversation
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.
Link to Ticket
Description of Changes Made
There was some code in the desktop menu to close it when moving away from the last item, but it wasn't reliably being applied. It previously depended on the
subnav-child-menu.htmltemplate being rendered, and on the site there are no menus being used at that level. In fact although you can add lower levels of menu items in the navigation config, this is clearly not expected as the menu does not render correctly in that scenario - we should probably tidy this up at some point but that's beyond the scope of this ticket.The new code I've applied here finds all the links in the drop down menu, regardless of the level, and simply closes the menu when the last one is focussed away from.
How to Test
In your local build, use keyboard navigation to tab through the menu and observe that the dropdown closes when you focus away from the last link. You may need to disable the caching in the header template.
Screenshots
Expand to see more
Screen.Recording.2026-02-19.at.09.39.19.mov
MR Checklist
Unit tests
Documentation
Browser testing
Data protection
Light and dark mode
Accessibility
Sustainability
Pattern library