-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Conversation
this.setState({ inputValue: "" }); | ||
Utils.safeInvoke(this.props.onAdd, value); | ||
const shouldClearInput = Utils.safeInvoke(this.props.onAdd, value); | ||
if (shouldClearInput) { |
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.
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
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.
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 NumericInput
s section on uncontrolled usage:
http://blueprintjs.com/docs/#core/components/forms/numeric-input.uncontrolled-mode
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.
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; |
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.
What about boolean | void
, so that you can return both true
or nothing if you want the tag to be added?
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.
Ah yep, missed that. Fixed. 👍
Add testsPreview: documentation |
Add/update testsPreview: documentation |
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.
👍 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. |
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.
shorter, same idea:
The input will be cleared after
onAdd
is invoked unless the callback explicitly returnsfalse
. This is useful if the providedvalue
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); | ||
|
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.
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 |
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.
how about pithy "only explicit return false cancels text clearing"
10ae44c
to
77e68be
Compare
@giladgray ready for re-review |
Respond to Gilad CR feedbackPreview: documentation |
Merge remote-tracking branch 'origin/master' into cl/taginput-1277Preview: documentation |
Fixes #1277
Checklist
Changes proposed in this pull request:
TagInput
onAdd
now returns aboolean
, that, iffalse
, will cause the input NOT to be cleared.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 ofTagInput
).Reviewers should focus on:
Does this behavior seem reasonable?