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

Commit 2d3ab6c

Browse files
authored
Merge pull request #140 from schmeusel/master
Strictly compare values of chips and not object references
2 parents 1971258 + 3387c78 commit 2d3ab6c

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/ChipInput.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,11 @@ class ChipInput extends React.Component {
262262
if (this.state.focusedChip == null && event.keyCode === 8) {
263263
this.setState({ focusedChip: chips[chips.length - 1] })
264264
} else if (this.state.focusedChip) {
265-
const index = chips.indexOf(this.state.focusedChip)
265+
const index = chips.findIndex((chip) => {
266+
return this.props.dataSourceConfig
267+
? this.state.focusedChip[this.props.dataSourceConfig.value] === chip[this.props.dataSourceConfig.value]
268+
: this.state.focusedChip === chip
269+
})
266270
const value = this.props.dataSourceConfig ? this.state.focusedChip[this.props.dataSourceConfig.value] : this.state.focusedChip
267271
this.handleDeleteChip(value, index)
268272
if (event.keyCode === 8 && index > 0) {
@@ -274,13 +278,21 @@ class ChipInput extends React.Component {
274278
}
275279
} else if (event.keyCode === 37) {
276280
const chips = this.props.value || this.state.chips
277-
const index = chips.indexOf(this.state.focusedChip)
281+
const index = chips.findIndex((chip) => {
282+
return this.props.dataSourceConfig
283+
? this.state.focusedChip[this.props.dataSourceConfig.value] === chip[this.props.dataSourceConfig.value]
284+
: this.state.focusedChip === chip
285+
})
278286
if (index > 0) {
279287
this.setState({ focusedChip: chips[index - 1] })
280288
}
281289
} else if (event.keyCode === 39) {
282290
const chips = this.props.value || this.state.chips
283-
const index = chips.indexOf(this.state.focusedChip)
291+
const index = chips.findIndex((chip) => {
292+
return this.props.dataSourceConfig
293+
? this.state.focusedChip[this.props.dataSourceConfig.value] === chip[this.props.dataSourceConfig.value]
294+
: this.state.focusedChip === chip
295+
})
284296
if (index >= 0 && index < chips.length - 1) {
285297
this.setState({ focusedChip: chips[index + 1] })
286298
} else {

0 commit comments

Comments
 (0)