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
  • #37977
Closed
Open
Issue created Jan 30, 2023 by Administrator@rootContributor2 of 2 checklist items completed2/2 checklist items

Dropdown: add an option to prevent focus on toggler via js show()

Created by: dp-sgr

Prerequisites

  • I have searched for duplicate or closed feature requests
  • I have read the contributing guidelines

Proposal

Add an options object or similar to the show() method of an dropdown instance. Via the options we could simply configure if the show method should focus the toggler of the dropdown or not.

Something like that would be very nice:

let dropdownInstance = window.bootstrap.Dropdown.getOrCreateInstance(togglerElement);

dropdownInstance.show({
   preventFocus: true
});

As a possible workaround i currently implemented this hack:

let dropdownInstance = window.bootstrap.Dropdown.getOrCreateInstance(togglerElement);

let focusFunc = togglerElement.focus;
togglerElement.focus = () => {
    /*do nothing*/
};

try {
    dropdownInstance.show();
} finally {
    togglerElement.focus = focusFunc;
}

Motivation and context

In some scenarious we don't want the toggler to be focused on dropdown show. In our specific use-case we have a custom autocomplete component which simply is a input-group of an text input and the dropdown toggler button.

By inserting chars to the text input (with a specific debounce time) the dropdown should be showed. But this currently leads to the issue of focusing the toggler.

https://github.com/twbs/bootstrap/blob/c735b2e196544b3bba25d645f4d725e8667b106c/js/src/dropdown.js#L151

Assignee
Assign to
Time tracking