Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • B bootstrap
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 263
    • Issues 263
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 114
    • Merge requests 114
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Bootstrap
  • bootstrap
  • Issues
  • #35496
Closed
Open
Issue created Dec 09, 2021 by Administrator@rootContributor3 of 3 checklist items completed3/3 checklist items

ESC key in DropDown no longer sets focus back to the toggle button in 5.1x

Created by: mtavares628

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

This is a regression from v5.02 which correctly sets the focus back

To reproduce:

  • go to https://getbootstrap.com/docs/5.1/components/dropdowns/
  • open a dropdown
  • use cursor/arrow keys or TAB to get focus into the menu
  • press ESC

Expected:

  • the dropdown is closed and focus is reset to the dropdown trigger button

Actual:

  • the dropdown is closed, but focus is lost. This creates an accessibility issue for keyboard users.

This is a regression from v5.02, where this worked correctly (see https://getbootstrap.com/docs/5.0/components/dropdowns/)

In looking at the code for dropdown.js in both, it looks like the dataApiKeydownHandler was revamped. v5.02 has the following:

` const getToggleButton = () => this.matches(SELECTOR_DATA_TOGGLE$3) ? this : SelectorEngine.prev(this, SELECTOR_DATA_TOGGLE$3)[0];

  if (event.key === ESCAPE_KEY$2) {
    getToggleButton().focus();
    Dropdown.clearMenus();
    return;
  }`

v5.1.3 has this instead where the focus is not specifically set:

` const getToggleButton = this.matches(SELECTOR_DATA_TOGGLE$3) ? this : SelectorEngine.prev(this, SELECTOR_DATA_TOGGLE$3)[0]; const instance = Dropdown.getOrCreateInstance(getToggleButton);

  if (event.key === ESCAPE_KEY$2) {
    instance.hide();
    return;
  }`

Reduced test cases

Here is a CodePen highlighting the issue:

https://codepen.io/mtavares628/pen/LYzZxQM

Following steps of opening dropdown, navigating with the arrow keys and hitting escape doesn't set the focus back to the button.

What operating system(s) are you seeing the problem on?

Windows

What browser(s) are you seeing the problem on?

Chrome, Firefox, Microsoft Edge

What version of Bootstrap are you using?

v5.1.3

Assignee
Assign to
Time tracking