bootstrap-select icon indicating copy to clipboard operation
bootstrap-select copied to clipboard

Opening dropdown does not scroll to selected option first time, but does second time

Open davidenco opened this issue 1 year ago • 4 comments

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/

davidenco avatar Jul 28 '23 16:07 davidenco

have you tried this version? Maybe works... I hope...

https://gist.github.com/mattymatty76/c996d3b77f298b2ec133be59992df9d4

#2837

mattymatty76 avatar Jul 28 '23 18:07 mattymatty76

have you tried this version? Maybe works... I hope...

https://snippet.host/ympdgo

#2837

Nope, sorry. I've updated the JSFiddle, but the same issue is happening:

https://jsfiddle.net/L04192pd/1/

davidenco avatar Aug 08 '23 14:08 davidenco

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();
    }
});

davidenco avatar Aug 11 '23 08:08 davidenco

Added PR #2841

davidenco avatar Aug 11 '23 08:08 davidenco