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.