-
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
Adding addOnBlur to TagInput #1966
Changes from 9 commits
7e4efa7
564e0fa
d89af14
dc6d6ac
3724a35
e26bd17
b8167a5
1f1ba22
6f2ce83
ea24d7b
379fc43
94977c0
e7f679d
29cbd68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,31 @@ describe("<TagInput>", () => { | |
assert.deepEqual(onAdd.args[0][0], [NEW_VALUE]); | ||
}); | ||
|
||
it("is invoked on blur when addOnBlur is true", done => { | ||
const onAdd = sinon.stub(); | ||
const wrapper = mount(<TagInput values={VALUES} addOnBlur={true} onAdd={onAdd} />); | ||
// simulate typing input text | ||
wrapper.setProps({ inputProps: { value: NEW_VALUE } }); | ||
wrapper.find("input").simulate("change", { currentTarget: { value: NEW_VALUE } }); | ||
const fakeEvent = { flag: "yes" }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, yeah I can just call simulate("blur") |
||
wrapper.simulate("blur", fakeEvent); | ||
setTimeout(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Add a comment explaining why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added comment |
||
assert.isTrue(onAdd.calledOnce); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("is not invoked on blur when addOnBlur is false", done => { | ||
const onAdd = sinon.stub(); | ||
const wrapper = mount(<TagInput values={VALUES} inputProps={{ value: NEW_VALUE }} onAdd={onAdd} />); | ||
const fakeEvent = { flag: "yes" }; | ||
wrapper.simulate("blur", fakeEvent); | ||
setTimeout(() => { | ||
assert.isTrue(onAdd.notCalled); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("does not clear the input if onAdd returns false", () => { | ||
const onAdd = sinon.stub().returns(false); | ||
const wrapper = mountTagInput(onAdd); | ||
|
@@ -383,8 +408,8 @@ describe("<TagInput>", () => { | |
function createInputKeydownEventMetadata(value: string, which: number) { | ||
return { | ||
currentTarget: { value }, | ||
// Enzyme throws errors if we don't mock the preventDefault method. | ||
preventDefault: () => { | ||
// Enzyme throws errors if we don't mock the stopPropagation method. | ||
stopPropagation: () => { | ||
return; | ||
}, | ||
which, | ||
|
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.
Don't think the word
also
is necessary here, especially since this is the first prop in the list. I think it reads more clearly without it.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.
Fixed