Skip to content

Commit

Permalink
fix: prevent modelValue update on initial render
Browse files Browse the repository at this point in the history
  • Loading branch information
rhmkstk committed Jul 22, 2024
1 parent 7550655 commit 4e9c50e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/vue/src/components/MultiSelect/LuiMultiSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ function setInitialSelectedOption() {
return
selectedOptions.value = parseModelValue(initialOption)
emit('update:modelValue', parseModelValue(initialOption))
// emit('update:modelValue', parseModelValue(initialOption))
}
function handleSearchState() {
if (!optionsActive.value)
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/components/Select/LuiSelect.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ export const Change: Story = {
components: { LuiSelect },
setup() {
const selectedName = ref('')
const consoleLog = () => console.warn('selectedName: ', selectedName)
const consoleLog = (e: any) => console.warn('selectedName: ', e)
return { selectedName, consoleLog }
},
template: changeTemplate,
Expand Down
11 changes: 7 additions & 4 deletions packages/vue/src/components/Select/LuiSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ function focusAvailableElement(
})
}
function updateSelectedOption(option: ModelValue) {
if (isFirstUpdate)
isFirstUpdate = false
if (option === undefined)
return
const optionText = typeof option !== 'string' ? option.text : option
Expand All @@ -267,11 +270,11 @@ function updateSelectedOption(option: ModelValue) {
typeof i !== 'string' ? i.text === optionText : i === optionText,
)
}
emit('update:modelValue', optionValue)
if (!isFirstUpdate)
if (!isFirstUpdate) {
emit('change', optionValue)
if (isFirstUpdate)
isFirstUpdate = false
emit('update:modelValue', optionValue)
}
}
function focusButton() {
Expand Down

0 comments on commit 4e9c50e

Please sign in to comment.