Skip to content
This repository was archived by the owner on Dec 23, 2022. It is now read-only.

Commit 461a80b

Browse files
committed
Don't clear the input when onBeforeRequestAdd returns false.
Fixes #161
1 parent 766a361 commit 461a80b

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/ChipInput.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ class ChipInput extends React.Component {
152152
if (newChipKeyCodes.indexOf(event.keyCode) >= 0 && event.target.value) {
153153
event.preventDefault()
154154
this.handleAddChip(event.target.value)
155-
this.autoComplete.setState({ searchText: '' })
156155
this.autoComplete.forceUpdate()
157156
} else {
158157
handleKeyDown(event)
@@ -165,10 +164,6 @@ class ChipInput extends React.Component {
165164
const index = parseInt(child.key, 10)
166165
const chosenRequest = dataSource[index]
167166
this.handleAddChip(chosenRequest)
168-
169-
this.autoComplete.setState({
170-
searchText: ''
171-
})
172167
this.autoComplete.forceUpdate()
173168
this.autoComplete.close()
174169

@@ -328,7 +323,7 @@ class ChipInput extends React.Component {
328323

329324
handleAddChip (chip) {
330325
if (this.props.onBeforeRequestAdd && !this.props.onBeforeRequestAdd(chip)) {
331-
return this.setState({ preventChipCreation: true, inputValue: this.autoComplete.state.searchText })
326+
return this.setState({ preventChipCreation: true })
332327
}
333328
this.autoComplete.setState({ searchText: '' })
334329
const chips = this.props.value || this.state.chips

stories/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@ storiesOf('ChipInput', module)
232232
allowDuplicates
233233
/>
234234
)
235+
.add('with onBeforeRequestAdd returning false', () =>
236+
<ChipInput
237+
defaultValue={['foo', 'bar', 'foo', 'bar']}
238+
onBeforeRequestAdd={() => false}
239+
/>
240+
)
235241
.add('tabbing between fields', () =>
236242
<form>
237243
<ChipInput

0 commit comments

Comments
 (0)