2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-06-19 09:50:33 +03:00

feat: add deselectFromDropdown boolean prop (#1033)

This commit is contained in:
andreas
2021-10-17 19:47:06 +03:00
committed by GitHub
parent caf8a34e09
commit 68da1c172e
5 changed files with 99 additions and 1 deletions
+53
View File
@@ -51,6 +51,7 @@ describe('Removing values', () => {
it('will not emit input event if value has not changed with backspace', () => {
const Select = mountDefault()
Select.vm.$data._value = 'one'
Select.findComponent({ ref: 'search' }).trigger('keydown.backspace')
expect(Select.emitted().input.length).toBe(1)
@@ -59,6 +60,58 @@ describe('Removing values', () => {
expect(Select.emitted().input.length).toBe(1)
})
it('should deselect a selected option when clicked and deselectFromDropdown is true', async () => {
const Select = selectWithProps({
value: 'one',
options: ['one', 'two', 'three'],
deselectFromDropdown: true,
})
const deselect = spyOn(Select.vm, 'deselect')
Select.vm.open = true
await Select.vm.$nextTick()
Select.find('.vs__dropdown-option--selected').trigger('click')
await Select.vm.$nextTick()
expect(deselect).toHaveBeenCalledWith('one')
})
it('should not deselect a selected option when clicked if clearable is false', async () => {
const Select = selectWithProps({
value: 'one',
options: ['one', 'two', 'three'],
clearable: false,
deselectFromDropdown: true,
})
const deselect = spyOn(Select.vm, 'deselect')
Select.vm.open = true
await Select.vm.$nextTick()
Select.find('.vs__dropdown-option--selected').trigger('click')
await Select.vm.$nextTick()
expect(deselect).not.toHaveBeenCalledWith('one')
})
it('should not deselect a selected option when clicked if deselectFromDropdown is false', async () => {
const Select = selectWithProps({
value: 'one',
options: ['one', 'two', 'three'],
deselectFromDropdown: false,
})
const deselect = spyOn(Select.vm, 'deselect')
Select.vm.open = true
await Select.vm.$nextTick()
Select.find('.vs__dropdown-option--selected').trigger('click')
await Select.vm.$nextTick()
expect(deselect).not.toHaveBeenCalledWith('one')
})
describe('Clear button', () => {
it('should be displayed on single select when value is selected', () => {
const Select = selectWithProps({