Skip to content

Conversation

@yp
Copy link
Collaborator

@yp yp commented Nov 7, 2017

…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:

  • Documentation N/A
  • Tests
  • Ready to be merged
  • Added myself to contributors table

…em is selected but only when prop 'selectedItem' is updated.
@codecov-io
Copy link

codecov-io commented Nov 7, 2017

Codecov Report

Merging #252 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #252   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           4      4           
  Lines         296    299    +3     
  Branches       71     72    +1     
=====================================
+ Hits          296    299    +3
Impacted Files Coverage Δ
src/downshift.js 100% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 22ed3d7...f69b1e3. Read the comment docs.

Copy link
Member

@kentcdodds kentcdodds left a 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,
Copy link
Member

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')
? ''
Copy link
Member

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?

Copy link
Collaborator Author

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.

Copy link
Member

@kentcdodds kentcdodds left a 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?

@arahansen
Copy link
Contributor

@kentcdodds Would you prefer a prop compared to a next branch or a 2.0-alpha type release?

@kentcdodds
Copy link
Member

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.

@yp
Copy link
Collaborator Author

yp commented Nov 8, 2017

What about introducing a new prop (say resetInputValue) that indicates what to do when resetting? For example null (default) forces the use of itemToString while if it is a string it is used as the new inputValue.

@kentcdodds
Copy link
Member

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 inputValue if they can...

@yp
Copy link
Collaborator Author

yp commented Nov 8, 2017

This is a sensible position. I am fine with either solution (opt-in or next/alpha branch).

@kentcdodds
Copy link
Member

Let's go with the opt-in. Thank you so much!

Copy link
Member

@kentcdodds kentcdodds left a 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:

  1. Let's document this somewhere in the README. Maybe it's own section? Wherever makes sense.
  2. 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 &&
Copy link
Member

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 👍

Copy link
Collaborator Author

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.

Copy link
Member

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!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@yp
Copy link
Collaborator Author

yp commented Nov 9, 2017

Sorry, I forgot to comment the new commits.

  1. Could you please write yourself the new prop? I am not confident in being able to do a good job. (I think you should be able to contribute to this PR.)
  2. I forgot the examples. I'll do something tomorrow.
    Thanks for your work.

@yp
Copy link
Collaborator Author

yp commented Nov 9, 2017

BTW, I prefixed the prop name with v2 in order to be clear about the version in which the breaking change will appear. I can revert to the unprefixed version if you wish so.

@kentcdodds
Copy link
Member

BTW, I prefixed the prop name with v2 in order to be clear about the version in which the breaking change will appear. I can revert to the unprefixed version if you wish so.

I don't mind it, but I do feel it's a little redundant. All properties in breakingChanges will be broken in v2. I don't expect anything to be v3 in that object.

Could you please write yourself the new prop? I am not confident in being able to do a good job. (I think you should be able to contribute to this PR.)

Sure, I can do that 👍

@kentcdodds kentcdodds merged commit 831aeab into downshift-js:master Nov 12, 2017
@kentcdodds
Copy link
Member

Thank you so much @yp! 🎉

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

Successfully merging this pull request may close these issues.

4 participants