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

bug (?): scroll position inside list is not reset when clearing the list #234

Open
jimniels opened this issue Mar 11, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@jimniels
Copy link

I'm not sure if this is intended behavior, but when you filter down the list to an item that's near the bottom of the list, then clear your search filter, all the results return but the scroll position of the list is not reset to the top.

Take a look at the example from the project's home page:

  • Switch to Vercel example
  • (Note that the last item in the list is "Contact Support")
  • Ensure the list scrolled to the top
  • Type in "Contact" and see the list filtered down to a single item
  • Select all text in the input box and delete it
  • See that "Contact" is on-screen (and the scroll position of the list is not back at the top, where it was when you started filtering your results)
CleanShot.2024-03-11.at.11.05.09.mp4

This seems unexpected to me. Whenever I clear my search query, I expect to the scroll position of the results list to always be reset to the top of the list.

@triptu
Copy link

triptu commented May 10, 2024

workaround i'm using for this -

const listRef = useRef<HTMLDivElement>(null);

const scrollUpWhenCleared = useCallback((value: string) => {
    if (value === "") {
      requestAnimationFrame(() => {
        listRef.current?.scrollTo({ top: 0 });
      });
    }
  }, []);

<Command.List ref={listRef}>

<Command.Input  onValueChange={scrollUpWhenCleared} >...

#233 looks similar.

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

3 participants