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

Select box smooth scrolls to current item when opening #93

Closed
mattgodbolt opened this issue May 19, 2021 · 5 comments
Closed

Select box smooth scrolls to current item when opening #93

mattgodbolt opened this issue May 19, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@mattgodbolt
Copy link

Describe the bug
In a long dropdown, the currently selected item is scrolled-to when opening the dropdown. This is wanted behaviour, but if the dropdown was previously scrolled there's an animation from the old position to the selected item position.

To Reproduce
Steps to reproduce the behavior:

  1. Make a large list (~200)
  2. Select an element at the top
  3. Reopen the list
  4. Scroll to the bottom
  5. Close the list (without picking anything)
  6. Reopen the list and observe the dizzzying zoom-scroll from the bottom all the way to the top

Expected behavior
Open opening at step 6 the dropdown should be centred about the selected item already without any motion.

Additional context
Version: 1.7.1

@mattgodbolt mattgodbolt added the bug Something isn't working label May 19, 2021
@oyejorge
Copy link
Member

It looks like calling this.scrollToOption(this.activeOption); in the close() method will fix this but I'm gonna test it out some more

@mattgodbolt
Copy link
Author

Thanks!

@oyejorge
Copy link
Member

oyejorge commented May 21, 2021

I didn't like my previous idea. Went with the above change. This also uses a new scroll(scrollTop, behavior) method that you could use. So instead of

this.tomSelect.dropdown_content.style.scrollBehavior = 'auto';
optionElement = this.tomSelect.getOption(value);
this.tomSelect.dropdown_content.scrollTop += (optionElement.offsetTop - elemTop);
this.tomSelect.dropdown_content.style.scrollBehavior = 'smooth';

you could do this

optionElement = this.tomSelect.getOption(value);
var scrollTop = this.tomSelect.dropdown_content.scrollTop + (optionElement.offsetTop - elemTop);
this.tomSelect.scroll( scrollTop, 'auto');

Gonna test a little more tomorrow

@oyejorge
Copy link
Member

ok, I like how things are working. Should be all set with 1.7.2!

@mattgodbolt
Copy link
Author

fab; thanks. We'll give it a go!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants