Skip to content

fix: do not falsely consider a selected option to be absent if it was added and selected at the same time #447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion src/composables/useOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,11 @@ export default function useOptions (props, context, dep)
}
})

watch(ev, (newValue) => {
// `eo` is used in `getOption`.
// `getOption` is used in `makeInternal`.
// `makeInternal` in this the callback`
// Therefore `eo` must be declared as source.
watch([ev, eo], ([newValue, _]) => {
if (isNullish(newValue)) {
update(makeInternal(newValue), false)
return
Expand Down
32 changes: 31 additions & 1 deletion tests/unit/Multiselect.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { createSelect, destroy, keyup, keydown, findAll, getValue } from 'unit-test-helpers'
import { toBeVisible } from '@testing-library/jest-dom/matchers'
import { nextTick } from 'vue'
import { ref, nextTick, version } from 'vue'
import Multiselect from './../../src/Multiselect.vue'
import { mount } from '@vue/test-utils'
import testSearch from './helpers/testSearch'

expect.extend({toBeVisible})

const describeVue3Only = (version.startsWith('3') ? describe : describe.skip)

describe('Multiselect', () => {
describe('General', () => {
it('should render Multiselect', () => {
Expand Down Expand Up @@ -686,5 +690,31 @@ describe('Multiselect', () => {
expect(getValue(select)).toStrictEqual([0,1])
})
})

describeVue3Only('Composition API', () => {
// This test is only possible with Vue 3 because the Composition API is used.
it('show selected option when added', async () => {
const values = ref(['option1'])
const options = ref(['option2'])

const wrapper = mount(Multiselect, {
props: {
mode: 'tags',
value: values,
options: options,
// this is the default, it is set to highlight the fact
allowAbsent: false,
},
})

options.value = ['option1', 'option2']
values.value = ['option1', 'option2']

await nextTick()

const selectedValues = wrapper.findAll(".multiselect-tag").map(tag => tag.text())
expect(selectedValues).toEqual(['option1', "option2"])
})
})
})
})