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

Feature Request: Reset downshift state when inputValue changes #664

Closed
bkilrain opened this issue Feb 11, 2019 · 5 comments
Closed

Feature Request: Reset downshift state when inputValue changes #664

bkilrain opened this issue Feb 11, 2019 · 5 comments

Comments

@bkilrain
Copy link

  • downshift version: 3.1.12
  • node version: 8.11.1
  • npm (or yarn) version: 5.6.0

Relevant code or config

What you did:

I'm using Downshift to render the dropdown for an autocomplete component. The defaultHighlightedIndex is set to 0 so that there is always a 'highlighted' item in the dropdown.

What happened:

If I hover an item lower in the list (index 4 or 5), however, and type to filter out possible items to a number less than the highlightedIndex, the highlightedIndex state does not update to ensure a highlighted item is still rendered in the dropdown.

Steps to Reproduce:

Code Sandbox Link

  1. Type 'a' into the input
  2. Hover over the last item in the list to set the highlightedIndex
  3. Type 'p'
  4. Notice the highlightedIndex doesn't update to highlight the top item

Suggested solution:

Right now, I'm calling reset() on every input change to get around this. As far as changes to the library, perhaps we could compare the highlightedIndex with the itemCount to make sure a highlighted item is being rendered at all times? Or add the inputChange event to cases where downshift's state is reset. Can anyone think of a usecase where they don't want downshift state to reset on inputChange?

@silviuaavram
Copy link
Collaborator

silviuaavram commented Feb 11, 2019

Thank you for the improvement request @bkilrain . I'd be happy to see this solved in our library so every user can benefit from it. Are you up for a Pull Request? :)

I won't lie, I'd be happy to see this change asap in Downshift, as I need it in Stardust as well. But I'd be happier if the change will be done by anyone else than me, so we can grow Downshift community more.

@bkilrain
Copy link
Author

Yep - I'm happy to take this on. To be clear, we just want to reset Downshift state when inputValue changes?

@silviuaavram
Copy link
Collaborator

I don't think we need to do all of that. As I understand, the issue is to reset only the highlightedIndex to the defaultHighlightedIndex each time the input value changes. Am I correct?

Resetting the whole state will probably mean other state stuff reset which we may not want to reset, like the selected item.

@bkilrain
Copy link
Author

Ok - fair enough.

@kilrain
Copy link
Contributor

kilrain commented Feb 17, 2019

Hey there - I've completed the fix but I'm getting this error when I run the setup script. I'll cut a PR anyways... just want to let you know.

Also, I'll submit from my work github account. Thanks!

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

No branches or pull requests

3 participants