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

Controlling what happens onBlur #577

Closed
jamestalmage opened this issue Sep 14, 2018 · 4 comments
Closed

Controlling what happens onBlur #577

jamestalmage opened this issue Sep 14, 2018 · 4 comments

Comments

@jamestalmage
Copy link

If the user tabs out of the drop down, it always selects the last selected item - even if they've completely typed out a different value.

I think it would be beneficial to add another function that deals with what to do when the focus leaves the component (either because of tabbing out or clicking outside). I am looking at using it in two different spots, and in one case I want to just select the first prediction on blur, in another - I want to just leave what they typed.

@jamestalmage
Copy link
Author

jamestalmage commented Sep 14, 2018

Notice how it reverts to "Foo", even though I've typed out "Food"
out

@hungrymonkey
Copy link

I believe you did not create any boundaries for your last item. Even if you click outside, it will select the last element.

If you were clicking outside, Downshift should reset by triggering the mouseUp state
.
To change the default behavior of clicking outside, you need to modify the stateReducer
https://github.com/paypal/downshift#statereducer

I do not know how to tab out.

@jamestalmage
Copy link
Author

Looks like I can figure out what I want to do with stateReducer.

Only pain point is that there is no access to highlightedItem (i.e. - that's not a property that is recorded in the state).

It seems like you could capture the currently highlighted option when they call getItemProps.

@kentcdodds
Copy link
Member

I think the workarounds are sufficient for this scenario. Make sure to checkout this example as well: https://codesandbox.io/s/github/kentcdodds/downshift-examples/tree/master/?module=%2Fsrc%2Fordered-examples%2F03-typeahead.js&moduleview=1

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

No branches or pull requests

3 participants