bootstrap-select
bootstrap-select copied to clipboard
Opening dropdown does not scroll to selected option first time, but does second time
I'm using Beta 2 to demonstrate this bug, because I cannot run the "dev" version on JSFiddle that fixes the LabelLabel bug from Beta 3.
The dropdown renders with an option selected. But when I click to open the dropdown, it does not show the selected option, but instead the list is at the top. However, close the dropdown and click to open it again and this time it will be scrolled to the selected option.
https://jsfiddle.net/rg2psc1n/
have you tried this version? Maybe works... I hope...
https://gist.github.com/mattymatty76/c996d3b77f298b2ec133be59992df9d4
have you tried this version? Maybe works... I hope...
https://snippet.host/ympdgo
Nope, sorry. I've updated the JSFiddle, but the same issue is happening:
https://jsfiddle.net/L04192pd/1/
Sorted! By adding the line in highlighted below, this fixed the issue in that when the dropdown opens, the list scrolls to the selected option so it displays in the middle. See updated JSFiddle (https://jsfiddle.net/cvnjmx20/).
this.$element.on('shown' + EVENT_KEY, function() {
that.createView(false, true); // <-- add this line here
if (that.$menuInner[0].scrollTop !== that.selectpicker.view.scrollTop)
{
that.$menuInner[0].scrollTop = that.selectpicker.view.scrollTop;
}
if (version.major > 3)
{
requestAnimationFrame(checkPopperExists);
}
else
{
setFocus();
}
});
Added PR #2841