Skip to content
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
8 changes: 8 additions & 0 deletions docs/content/api/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ Triggered when the dropdown is closed.
this.$emit("close");
```

## `clear`

Triggered when clear button clicked, cleared value passed as an argument.

```js
this.$emit("clear", selectedOption);
```

## `option:selecting` <Badge text="v3.11.0+" />

Triggered after an option has been selected, <strong>before</strong> updating internal state.
Expand Down
5 changes: 4 additions & 1 deletion src/components/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export default {
'open',
'close',
'update:modelValue',
'clear',
'search',
'search:compositionstart',
'search:compositionend',
Expand Down Expand Up @@ -1044,10 +1045,12 @@ export default {
},

/**
* Clears the currently selected value(s)
* Clears the currently selected value(s),
* triggers the clear event and passes cleared value as argument
* @return {void}
*/
clearSelection() {
this.$emit('clear', this.$data._value)
this.updateValue(this.multiple ? [] : null)
},

Expand Down
1 change: 1 addition & 0 deletions tests/unit/Deselecting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ describe('Removing values', () => {

expect(Select.emitted()['update:modelValue']).toEqual([[null]])
expect(Select.vm.selectedValue).toEqual([])
expect(Select.emitted()['clear']).toEqual([['foo']])
})

it('should be disabled when component is disabled', () => {
Expand Down