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

[TagInput] onAdd can return false to prevent clearing input #1309

Merged
merged 7 commits into from
Jul 7, 2017

Conversation

cmslewis
Copy link
Contributor

Fixes #1277

Checklist

  • Include tests

Changes proposed in this pull request:

  • Changed TagInput onAdd now returns a boolean, that, if false, will cause the input NOT to be cleared.
    • This is useful, for example, if the provided value is somehow invalid and should not be added as a tag (though whether or not the tag is added is the consumer's concern, due to the strictly controlled nature of TagInput).

Reviewers should focus on:

Does this behavior seem reasonable?

@cmslewis cmslewis added this to the 1.22.0 milestone Jun 30, 2017
@cmslewis cmslewis requested review from llorca and giladgray June 30, 2017 22:18
@cmslewis cmslewis changed the title [TagInput] Return boolean from onAdd that clears input if true [TagInput] Return boolean from onAdd that clears input only if true Jun 30, 2017
this.setState({ inputValue: "" });
Utils.safeInvoke(this.props.onAdd, value);
const shouldClearInput = Utils.safeInvoke(this.props.onAdd, value);
if (shouldClearInput) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a switch in the examples for "Unique values" 👍

Can also come as a follow up PR, happy to take care of this

Copy link
Contributor Author

@cmslewis cmslewis Jun 30, 2017

Choose a reason for hiding this comment

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

I'm iffy on adding a "unique values" switch, because it's doesn't correspond to out-of-the-box behavior. Would love to figure out a good way to communicate how to do that in a future PR though. Maybe we could just include a code snippet similar to NumericInputs section on uncontrolled usage:

http://blueprintjs.com/docs/#core/components/forms/numeric-input.uncontrolled-mode

Copy link
Contributor

@llorca llorca Jun 30, 2017

Choose a reason for hiding this comment

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

That's fair, I mean I guess the documentation speaks for itself now, we really were lacking this return false capability

*/
onAdd?: (value: string) => void;
onAdd?: (value: string) => boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

What about boolean | void, so that you can return both true or nothing if you want the tag to be added?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yep, missed that. Fixed. 👍

@blueprint-bot
Copy link

Add tests

Preview: documentation
Coverage: core | datetime

@blueprint-bot
Copy link

Add/update tests

Preview: documentation
Coverage: core | datetime

Copy link
Contributor

@giladgray giladgray left a comment

Choose a reason for hiding this comment

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

👍 just clean up docs language

*
* By default, the input will be cleared after `onAdd` is invoked. However, if the `onAdd`
* function returns `false`, the input will _not_ be cleared. This is useful, for example,
* if the provided `value` is somehow invalid and should not be added as a tag.
Copy link
Contributor

Choose a reason for hiding this comment

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

shorter, same idea:

The input will be cleared after onAdd is invoked unless the callback explicitly returns false. This is useful if the provided value is somehow invalid and should not be added as a tag.

this.setState({ inputValue: "" });
Utils.safeInvoke(this.props.onAdd, value);
const shouldClearInput = Utils.safeInvoke(this.props.onAdd, value);

Copy link
Contributor

Choose a reason for hiding this comment

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

unnecessary whitespace as next block is directly related to variable definition: continuing the thought.

const shouldClearInput = Utils.safeInvoke(this.props.onAdd, value);

// strict equal is necessary to ensure the input is cleared whether the return value is
// true or undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

how about pithy "only explicit return false cancels text clearing"

@giladgray giladgray changed the title [TagInput] Return boolean from onAdd that clears input only if true [TagInput] onAdd can return false to prevent clearing input Jul 1, 2017
@cmslewis cmslewis force-pushed the cl/taginput-1277 branch from 10ae44c to 77e68be Compare July 4, 2017 20:54
@cmslewis
Copy link
Contributor Author

cmslewis commented Jul 4, 2017

@giladgray ready for re-review

@blueprint-bot
Copy link

Respond to Gilad CR feedback

Preview: documentation
Coverage: core | datetime

@adidahiya adidahiya dismissed giladgray’s stale review July 7, 2017 21:36

addressed feedback

@blueprint-bot
Copy link

Merge remote-tracking branch 'origin/master' into cl/taginput-1277

Preview: documentation
Coverage: core | datetime

@adidahiya adidahiya merged commit 4ec5f41 into master Jul 7, 2017
@adidahiya adidahiya deleted the cl/taginput-1277 branch July 7, 2017 21:44
@llorca llorca mentioned this pull request Jul 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants