Skip to content

Commit

Permalink
fix: Selecting a group may cause selection of duplicate items (shenta…
Browse files Browse the repository at this point in the history
…o#945) (shentao#969)

* fix: Selecting a group may cause selection of duplicate items (shentao#945)

* Added test-case for scenario described in issue shentao#945
  • Loading branch information
akki-jat authored and shentao committed Apr 27, 2019
1 parent 8c162dd commit 8c88b82
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/multiselectMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,9 @@ export default {

this.$emit('input', newValue, this.id)
} else {
const optionsToAdd = group[this.groupValues].filter(not(this.isOptionDisabled || this.isSelected))
const optionsToAdd = group[this.groupValues].filter(
option => !(this.isOptionDisabled(option) || this.isSelected(option))
)

this.$emit('select', optionsToAdd, this.id)
this.$emit(
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/Multiselect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,25 @@ describe('Multiselect.vue', () => {
wrapper.vm.select(wrapper.vm.filteredOptions[0])
expect(wrapper.emitted().input).toEqual([[[], null]])
})
test('should not add duplicate values to selected array', () => {
const wrapper = shallowMount(Multiselect, {
propsData: {
value: ['Value 1'],
options: [
{ label: 'Label 1', values: ['Value 1', 'Value 2'] },
{ label: 'Label 2', values: ['Value 3', 'Value 4'] }
],
multiple: true,
groupValues: 'values',
groupLabel: 'label',
groupSelect: true
}
})
wrapper.vm.select(wrapper.vm.filteredOptions[0])
expect(wrapper.emitted().input).toEqual([
[['Value 1', 'Value 2'], null]
])
})
})
describe('when selecting a group label, groupSelect == TRUE and $isDisabled == TRUE', () => {
test('should add values to selected array except disabled values', () => {
Expand Down

0 comments on commit 8c88b82

Please sign in to comment.