Keyboard navigation in dropdowns with auto-close outside behavior leaves multiple dropdowns shown
Nobody has claimed this yet.
- Dominant language
- MDX
- Stars
- 175k
- Forks
- 78.6k
- Avg merge
- 7h 19m
- Merged PRs (30d)
- 35
Description
Prerequisites
- I have searched for duplicate or closed issues
- I have validated any HTML to avoid common problems
- I have read the contributing guidelines
Describe the issue
In a top level menu with multiple sub-menu dropdowns configured to use the data-bs-auto-close="outside", it is possible to end up with more than one sub-menu being displayed and overlapped on the screen at the same time. The prior menus are not auto-closing as expected.
Steps to recreate (using example menu listed in Reduced test cases)
- Click on Demo top level menu
- Click on Submenu 3. See that its items are shown.
- Use the up arrow key multiple times to navigate focus back up through Submenu 2 and 1. Note that now all sub-menus are being shown and none have closed.
Code that may be causing this behavior is in dropdown.js, dataApiKeydownHandler under
if (isUpOrDownEvent) {
event.stopPropagation();
instance.show(); //This is potentially causing a re-show of the item we just left? If I comment out, I no longer see the undesired behavior.
instance._selectMenuItem(event);
return;
}
Reduced test cases
Given the following menu setup:
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false" id="menuDemo">Demo</a>
<ul class="dropdown-menu">
<li class="dropend">
<a class="dropdown-item dropdown-toggle " data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false" href="#" id="subMenuDemo1">Submenu 1</a>
<ul class="dropdown-menu dropdown-menu-end">
<li>Menu Item 1A</li>
<li>Menu Item 1B</li>
</ul>
</li>
<li class="dropend">
<a class="dropdown-item dropdown-toggle " data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false" href="#" id="subMenuDemo2">Submenu 2</a>
<ul class="dropdown-menu dropdown-menu-end">
<li>Menu Item 2A</li>
<li>Menu Item 2B</li>
<li>Menu Item 2C</li>
</ul>
</li>
<li class="dropend">
<a class="dropdown-item dropdown-toggle " data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false" href="#" id="subMenuDemo3">Submenu 3</a>
<ul class="dropdown-menu dropdown-menu-end">
<li>Menu Item 3A</li>
<li>Menu Item 3B</li>
</ul>
</li>
</ul>
</li>
What operating system(s) are you seeing the problem on?
Windows
What browser(s) are you seeing the problem on?
Chrome, Microsoft Edge (but suspect it is not browser dependent)
What version of Bootstrap are you using?
v5.3.7
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in dropdown.js at dataApiKeydownHandler, especially the isUpOrDownEvent branch and its instance.show() call. Reproduce the behavior with the reduced nested menu using data-bs-auto-close="outside" and keyboard navigation. Done means moving focus upward closes the previously opened submenus so multiple menus are not shown at once.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- html, javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100