mirror of
https://github.com/tenrok/vue-select.git
synced 2026-06-10 07:52:23 +03:00
feat: add deselectFromDropdown boolean prop (#1033)
This commit is contained in:
@@ -103,6 +103,8 @@
|
||||
role="option"
|
||||
class="vs__dropdown-option"
|
||||
:class="{
|
||||
'vs__dropdown-option--deselect':
|
||||
isOptionDeselectable(option) && index === typeAheadPointer,
|
||||
'vs__dropdown-option--selected': isOptionSelected(option),
|
||||
'vs__dropdown-option--highlight': index === typeAheadPointer,
|
||||
'vs__dropdown-option--disabled': !selectable(option),
|
||||
@@ -206,6 +208,16 @@ export default {
|
||||
default: true,
|
||||
},
|
||||
|
||||
/**
|
||||
* Can the user deselect an option by clicking it from
|
||||
* within the dropdown.
|
||||
* @type {Boolean}
|
||||
*/
|
||||
deselectFromDropdown: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
|
||||
/**
|
||||
* Enable/disable filtering the options.
|
||||
* @type {Boolean}
|
||||
@@ -960,7 +972,8 @@ export default {
|
||||
},
|
||||
|
||||
/**
|
||||
* Select a given option.
|
||||
* Select or deselect a given option.
|
||||
* Allow deselect if clearable or if not the only selected option.
|
||||
* @param {Object|String} option
|
||||
* @return {void}
|
||||
*/
|
||||
@@ -975,6 +988,11 @@ export default {
|
||||
}
|
||||
this.updateValue(option)
|
||||
this.$emit('option:selected', option)
|
||||
} else if (
|
||||
this.deselectFromDropdown &&
|
||||
(this.clearable || (this.multiple && this.selectedValue.length > 1))
|
||||
) {
|
||||
this.deselect(option)
|
||||
}
|
||||
this.onAfterSelect(option)
|
||||
},
|
||||
@@ -1090,6 +1108,13 @@ export default {
|
||||
)
|
||||
},
|
||||
|
||||
/**
|
||||
* Can the current option be removed via the dropdown?
|
||||
*/
|
||||
isOptionDeselectable(option) {
|
||||
return this.isOptionSelected(option) && this.deselectFromDropdown
|
||||
},
|
||||
|
||||
/**
|
||||
* Determine if two option objects are matching.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user