Skip to content

Fix nested dropdown keyboard leaving sibling submenus open#42694

Closed
aljojoby9 wants to merge 1 commit into
twbs:mainfrom
aljojoby9:fix/dropdown-keyboard-sibling-submenus
Closed

Fix nested dropdown keyboard leaving sibling submenus open#42694
aljojoby9 wants to merge 1 commit into
twbs:mainfrom
aljojoby9:fix/dropdown-keyboard-sibling-submenus

Conversation

@aljojoby9

Copy link
Copy Markdown

Description

When using nested dropdowns with data-bs-auto-close="outside", keyboard arrow navigation between submenu toggles can leave multiple submenus open at once. ArrowUp/ArrowDown on a nested toggle always called show() without closing sibling menus first.

This change closes other open menus (via clearMenus) when the keydown target is a dropdown toggle, then shows the focused submenu. Regular in-menu item arrow navigation is unchanged.

Motivation & Context

Fixes #41869.

Overlapping nested submenus during keyboard navigation is a real usability/accessibility problem in multi-level menus (navbars, app menus). A previous PR (#42528) proposed the same approach and was closed by the author without maintainer rejection.

Type of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the contributing guidelines
  • My code follows the code style of the project (npm run js-lint)
  • My change introduces changes to the documentation
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed

Tests

  • npx karma start js/tests/karma.conf.js --single-run → 810/810 SUCCESS
  • npx eslint js/src/dropdown.js js/tests/unit/dropdown.spec.js → no errors

When arrow keys target a nested dropdown toggle, close other open menus
first so only the focused submenu stays shown. Fixes overlapping menus
with autoClose "outside" during keyboard navigation.

Fixes twbs#41869
@aljojoby9
aljojoby9 requested a review from a team as a code owner July 16, 2026 12:57
Copilot AI review requested due to automatic review settings July 16, 2026 12:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an issue in Bootstrap’s dropdown keyboard navigation where moving between nested submenu toggles (notably with data-bs-auto-close="outside") could leave multiple sibling submenus open at the same time, causing overlapping menus.

Changes:

  • Update ArrowUp/ArrowDown keydown handling so that when the keydown originates from a dropdown toggle, other open menus are closed via Dropdown.clearMenus(event) before showing the newly focused submenu.
  • Add a unit test that reproduces the nested-submenu keyboard scenario and asserts sibling submenus are closed when opening another submenu via ArrowDown.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
js/src/dropdown.js Closes other open dropdown menus before showing a submenu when ArrowUp/ArrowDown is pressed on a dropdown toggle.
js/tests/unit/dropdown.spec.js Adds regression coverage ensuring sibling nested submenus don’t remain open during keyboard navigation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mdo

mdo commented Jul 16, 2026

Copy link
Copy Markdown
Member

v5 doesn't support nested menus—I don't think we need any changes in support of them?

@aljojoby9

Copy link
Copy Markdown
Author

Thanks @mdo — that makes sense. I opened this based on #41869, but if nested menus are out of scope for v5, I'm happy to close this PR.

Thanks for taking a look!

@aljojoby9 aljojoby9 closed this Jul 16, 2026
@mdo

mdo commented Jul 17, 2026

Copy link
Copy Markdown
Member

They're coming in v6 :). You're welcome to checkout the v6-dev branch and see if there's any improvements to make there!

@aljojoby9

Copy link
Copy Markdown
Author

Thanks @mdo — I'll take a look at the v6-dev branch for nested menu improvements!

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keyboard navigation in dropdowns with auto-close outside behavior leaves multiple dropdowns shown

4 participants