Skip to content

Comments

More reliably close the menu when focus moves away from the last item#417

Open
helenb wants to merge 2 commits intomainfrom
feature/sub-menu-behaviour-tweaks
Open

More reliably close the menu when focus moves away from the last item#417
helenb wants to merge 2 commits intomainfrom
feature/sub-menu-behaviour-tweaks

Conversation

@helenb
Copy link
Member

@helenb helenb commented Feb 19, 2026

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.html template 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

  • Add a description of your pull request and instructions for the reviewer to verify your work.
  • If your pull request is for a specific ticket, link to it in the description.
  • Stay on point and keep it small so the merge request can be easily reviewed.
  • Tests and linting passes.

Unit tests

  • Added
  • Not required

Documentation

Browser testing

  • I have tested in the following browsers and environments (edit the list as required)
    • Latest version of Chrome on mac
  • Not required

Data protection

  • Not relevant
  • This adds new sources of PII and documents it and modifies Birdbath processors accordingly

Light and dark mode

  • I have tested the changes in both light and dark mode
  • The change is not relevant to dark and light mode

Accessibility

  • Automated WCAG 2.1 tests pass
  • HTML validation passes
  • Manual WCAG 2.1 tests completed
  • I have tested in a screen reader
  • I have tested in high-contrast mode
  • Any animations removed for prefers-reduced-motion
  • Not required

Sustainability

  • Images are optimised and lazy-loading used where appropriate
  • SVGs have been optimised
  • Performance and transfer of data considered
  • If JavaScript is needed alternatives have been considered
  • Not required

Pattern library

  • The pattern library component for this template displays correctly, and does not break parent templates
  • The styleguide is updated if relevant
  • Changes are not relevant the pattern library

@helenb helenb requested a review from chris-lawton February 19, 2026 09:44
@helenb helenb self-assigned this Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant