Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
davidenco opened this issue Jul 28, 2023 · 4 comments
Labels

Comments

@davidenco
Copy link

davidenco commented Jul 28, 2023

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 davidenco added the bug label Jul 28, 2023
@mattymatty76
Copy link

mattymatty76 commented Jul 28, 2023

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

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

#2837

@davidenco
Copy link
Author

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
Copy link
Author

davidenco commented Aug 11, 2023

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 added a commit to davidenco/bootstrap-select that referenced this issue Aug 11, 2023
…, but does second time

Fix for issue:

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. snapappointments#2838
@davidenco
Copy link
Author

Added PR #2841

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants