Skip to content

Commit a968f59

Browse files
committed
fix: do not falsely consider a selected option to be absent if it was added and selected at the same time
Fixes vueform#446
1 parent e07dad6 commit a968f59

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/composables/useOptions.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,11 @@ export default function useOptions (props, context, dep)
807807
}
808808
})
809809

810-
watch(ev, (newValue) => {
810+
// `eo` is used in `getOption`.
811+
// `getOption` is used in `makeInternal`.
812+
// `makeInternal` in this the callback`
813+
// Therefore `eo` must be declared as source.
814+
watch([ev, eo], ([newValue, _]) => {
811815
if (isNullish(newValue)) {
812816
update(makeInternal(newValue), false)
813817
return

tests/unit/Multiselect.spec.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { createSelect, destroy, keyup, keydown, findAll, getValue } from 'unit-test-helpers'
22
import { toBeVisible } from '@testing-library/jest-dom/matchers'
3-
import { nextTick } from 'vue'
3+
import { ref, nextTick, version } from 'vue'
4+
import Multiselect from './../../src/Multiselect.vue'
5+
import { mount } from '@vue/test-utils'
46
import testSearch from './helpers/testSearch'
57

68
expect.extend({toBeVisible})
79

10+
const describeVue3Only = (version.startsWith('3') ? describe : describe.skip)
11+
812
describe('Multiselect', () => {
913
describe('General', () => {
1014
it('should render Multiselect', () => {
@@ -686,5 +690,31 @@ describe('Multiselect', () => {
686690
expect(getValue(select)).toStrictEqual([0,1])
687691
})
688692
})
693+
694+
describeVue3Only('Composition API', () => {
695+
// This test is only possible with Vue 3 because the Composition API is used.
696+
it('show selected option when added', async () => {
697+
const values = ref(['option1'])
698+
const options = ref(['option2'])
699+
700+
const wrapper = mount(Multiselect, {
701+
props: {
702+
mode: 'tags',
703+
value: values,
704+
options: options,
705+
// this is the default, it is set to highlight the fact
706+
allowAbsent: false,
707+
},
708+
})
709+
710+
options.value = ['option1', 'option2']
711+
values.value = ['option1', 'option2']
712+
713+
await nextTick()
714+
715+
const selectedValues = wrapper.findAll(".multiselect-tag").map(tag => tag.text())
716+
expect(selectedValues).toEqual(['option1', "option2"])
717+
})
718+
})
689719
})
690720
})

0 commit comments

Comments
 (0)