Skip to content

Commit 2a3f307

Browse files
authored
fix: watch model changes on NeCombobox multiple (#32)
1 parent 3237e64 commit 2a3f307

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/components/NeCombobox.vue

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { faCheck as fasCheck } from '@fortawesome/free-solid-svg-icons'
1919
import { faXmark as fasXmark } from '@fortawesome/free-solid-svg-icons'
2020
import NeBadge from './NeBadge.vue'
2121
import { onClickOutside } from '@vueuse/core'
22-
import { uniqBy } from 'lodash-es'
22+
import { uniqBy, isEqual } from 'lodash-es'
2323
2424
export interface NeComboboxOption {
2525
id: string
@@ -165,8 +165,9 @@ onMounted(() => {
165165
watch(
166166
() => props.modelValue,
167167
() => {
168-
// watching modelValue with multiple selection causes a loop that degrades rendering performance
169-
if (!props.multiple) {
168+
if (props.multiple) {
169+
selectMultipleOptionsFromModelValue()
170+
} else {
170171
selectSingleOptionFromModelValue()
171172
}
172173
}
@@ -260,7 +261,11 @@ function selectMultipleOptionsFromModelValue() {
260261
selectedList.push(optionFound)
261262
}
262263
}
263-
selected.value = selectedList
264+
265+
// update selected list only if needed: this is needed to avoid loops that degrade performances
266+
if (!isEqual(selected.value, selectedList)) {
267+
selected.value = selectedList
268+
}
264269
}
265270
266271
function focus() {

0 commit comments

Comments
 (0)