Skip to content
This repository was archived by the owner on Dec 5, 2020. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/TagSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ class TagSelect extends React.Component {
})

this.setState({ value })
}

componentDidUpdate(prevProps) {
if (prevProps !== this.props) {
const value = {}
this.props.value.forEach((val) => {
value[val[[this.props.keyAttr]] || val] = val
})
this.setState({ value })
}
}

/**
Expand Down Expand Up @@ -92,7 +102,6 @@ class TagSelect extends React.Component {

const value = { ...this.state.value }
const found = this.state.value[key]

// Item is on array, so user is removing the selection
if (found) {
delete value[key]
Expand All @@ -106,7 +115,7 @@ class TagSelect extends React.Component {

value[key] = item
}

return this.setState({ value }, () => {
if (this.props.onItemPress) {
this.props.onItemPress(item)
Expand Down