-
Notifications
You must be signed in to change notification settings - Fork 944
If selectedItem is controlled, 'inputValue' is not updated when an it… #252
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
If selectedItem is controlled, 'inputValue' is not updated when an it… #252
Conversation
…em is selected but only when prop 'selectedItem' is updated.
Codecov Report
@@ Coverage Diff @@
## master #252 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 4 4
Lines 296 299 +3
Branches 71 72 +1
=====================================
+ Hits 296 299 +3
Continue to review full report at Codecov.
|
… not the inputValue).
kentcdodds
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think that I see where this is going. In your example, it does appear to be updating the inputValue to the selected item anyway. But the example doesn't demonstrate the behavior you want (setting the selectedItem to ''). Could you update the example so we can be sure what the experience looks like and that it's what you want? You could simply add a button to set it to an empty string or something.
Thanks so much for doing this!
| const changes = { | ||
| type: Downshift.stateChangeTypes.unknown, | ||
| selectedItem: itemToSelect, | ||
| inputValue: itemToSelect, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This requires that we publish a breaking change. I'm not averse to breaking changes, but I do like to avoid them (and do them in bulk) if I can... 🤔
src/downshift.js
Outdated
| selectedItem: item, | ||
| inputValue: this.props.itemToString(item), | ||
| inputValue: this.isControlledProp('selectedItem') | ||
| ? '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should reset to this.props.defaultInputValue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is indeed a good suggestion.
… selectedItem is a controlled prop.
…ponents to select different items from a list.
kentcdodds
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I have an idea. I want to avoid making a breaking change right now and I'd rather hold off until we have other breaking changes ready to go. So here's what a propose:
A new prop (Maybe called breakingChanges) that's an object which you can pass flags for behavior to opt-into things that will be breaking changes in the next release.
This way folks can enable these things and when the next major version happens, then they can simply remove the prop and everything will continue to work as before for them.
So it could be:
<Downshift breakingChanges={{resetInputOnSelection: true}} />Then in the code we'd reference this to know whether to continue with the current behavior or use the new behavior. We'd be able to document this opt-in support in one place and when it comes time to push a major version we can go throughout the codebase and remove all of these. I think it should be straightforward. What do you think?
|
@kentcdodds Would you prefer a prop compared to a |
|
I only use those when a breaking change is imminent. But I can't think of other things that justify a major release at this time, so I think this is a good compromise. I want to avoid API churn. |
|
What about introducing a new prop (say |
|
I'd considered that as well, but unless I'm mistaken, the current behavior would actually never be preferred, so I'd like to eventually get rid of it. Every prop we add comes with more complexity for the codebase and the API. So I'd rather go with a temporary prop if the behavior possible. But I could be wrong. Is there a common enough situation where someone wants the reset behavior to be something else? I'd rather defer people to controlling |
|
This is a sensible position. I am fine with either solution (opt-in or next/alpha branch). |
|
Let's go with the opt-in. Thank you so much! |
kentcdodds
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! This is looking good. 2 Things:
- Let's document this somewhere in the README. Maybe it's own section? Wherever makes sense.
- Could you make the examples use the new prop so we see the behavior?
Thanks! I'm feeling pretty good about this 👍
src/downshift.js
Outdated
| inputValue: this.props.itemToString(item), | ||
| inputValue: | ||
| this.isControlledProp('selectedItem') && | ||
| this.props.breakingChanges && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing the check for this.props.breakingChanges is unnecessary because the default prop is an empty object 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea was to be on the safe side in case someone erroneously specifies null. But it is up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I think that most people wont be using this prop and of those, not many will make it dynamic. I expect that folks will inline an object who want to use this prop, so let's just remove the check 👍 Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
Sorry, I forgot to comment the new commits.
|
|
BTW, I prefixed the prop name with |
I don't mind it, but I do feel it's a little redundant. All properties in
Sure, I can do that 👍 |
|
Thank you so much @yp! 🎉 |
…em is selected but only when prop 'selectedItem' is updated.
What: see issue #243
Why: see issue #243
How: inputValue is set to '' if selectedItem is a controlled prop when an item is selected.
Checklist: