Skip to content

Conversation

@VishalManole7
Copy link

Description

This PR fixes an issue where nested dropdown submenus using
data-bs-auto-close="outside"
can remain open simultaneously when navigating with keyboard arrow keys.

When moving focus upward (ArrowUp), Bootstrap’s dataApiKeydownHandler triggers a call to show(), which reopens the submenu the user just left. This results in multiple overlapping open submenus.

This fix ensures that only the submenu associated with the currently focused item remains open.

Root Cause

In dropdown.js, the following block always calls instance.show() when navigating with ArrowUp/ArrowDown:

if (isUpOrDownEvent) {
event.stopPropagation();
instance.show();
instance._selectMenuItem(event);
return;
}

This causes previously opened submenus to be reopened during keyboard navigation.

Fix Implemented

Only call show() when navigating downward into a submenu.

Prevent calling show() when navigating upward, allowing Bootstrap’s normal auto-close behavior to work.

// FIX: Prevent reopening submenus while navigating with arrow keys
if (isUpOrDownEvent) {
event.stopPropagation();

// Only open submenu when moving DOWN into it
if (event.key === 'ArrowDown' && !instance._menu.classList.contains('show')) {
instance.show();
}

instance._selectMenuItem(event);
return;
}

This ensures that only one submenu stays open at a time and fixes the overlapping submenu issue.

Steps to Reproduce (Before Fix)

  • Open a dropdown with nested submenus (dropend items).

  • Click to open Submenu 3.

  • Press ArrowUp multiple times.

  • Submenu 3, 2, and 1 all remain open simultaneously.

Expected Behavior (After Fix)

✔ Only one submenu remains open at a time
✔ Upward navigation no longer reopens previous submenus
✔ Normal mouse behavior is unchanged
✔ Keyboard accessibility is improved and consistent

Tested On

  • Windows

  • Chrome

  • Microsoft Edge

Works consistently across browsers.

Additional Notes

This change preserves Bootstrap’s existing navigation patterns while fixing a regression specific to nested dropdown keyboard navigation.

Type of changes

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

Checklist

  • I have read the contributing guidelines
  • My code follows the code style of the project (using npm run 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

@VishalManole7 VishalManole7 requested a review from a team as a code owner November 25, 2025 14:40
@julien-deramond
Copy link
Member

Thanks for creating a PR, @VishalManole7.
Please add the corresponding unit tests (or update existing ones when appropriate), unless it’s technically not possible. 🙏

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants