Search code examples
bootstrap-native

Bootstrap native: override setFocus on dropdown handling


Aside from forking the library, is there a way to override/disable setFocus in the private show and hide methods of the dropdown?

I am using the dropdown for a mini-cart on a sticky navbar. When an item is added I'd like the dropdown to open (which works fine) but the focus is jumping to the top of the page on show and hide. I realize this is a feature and not a bug! But for this feature I want to keep any scrolling from occurring.


Solution

  • The only thing you can do is to is to hook into the shown.bs.dropdown and hidden.bs.dropdown events and set a different focus element after a 20ms timeout, but this is very confusing for users who use or only use keyboard navigation.