Skip to content

Commit

Permalink
fix(TagsInput): avoid mutating modelValue directly (#1509)
Browse files Browse the repository at this point in the history
* fix: #1508

* Update TagsInputRoot.vue

* fix(TagsInputRoot): fix errors
  • Loading branch information
ploca14 authored Dec 19, 2024
1 parent cc5b2e8 commit ad43ecf
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/radix-vue/src/TagsInput/TagsInputRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ provideTagsInputRootContext({
}
if (props.duplicate) {
modelValue.value.push(payload)
modelValue.value = [...modelValue.value, payload]
return true
}
else {
const exist = modelValue.value.includes(payload)
if (!exist) {
modelValue.value.push(payload)
modelValue.value = [...modelValue.value, payload]
return true
}
else {
Expand All @@ -142,7 +142,7 @@ provideTagsInputRootContext({
},
onRemoveValue: (index) => {
if (index !== -1)
modelValue.value.splice(index, 1)
modelValue.value = modelValue.value.filter((_, i) => i !== index)
},
onInputKeydown: (event) => {
const target = event.target as HTMLInputElement
Expand All @@ -158,7 +158,7 @@ provideTagsInputRootContext({
if (selectedElement.value) {
const index = collection.findIndex(i => i === selectedElement.value)
modelValue.value.splice(index, 1)
modelValue.value = modelValue.value.filter((_, i) => i !== index)
selectedElement.value = selectedElement.value === lastTag ? collection.at(index - 1) : collection.at(index + 1)
event.preventDefault()
}
Expand Down

0 comments on commit ad43ecf

Please sign in to comment.