2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-06-22 10:30:34 +03:00

fix: emit input event only if there is val to be deleted (#1038)

This commit is contained in:
andreas
2020-03-16 04:17:25 +02:00
committed by GitHub
parent 0bad820f91
commit eedda74d43
2 changed files with 27 additions and 17 deletions
+2 -2
View File
@@ -819,7 +819,7 @@
* @return {this.value}
*/
maybeDeleteValue() {
if (!this.searchEl.value.length && this.selectedValue && this.clearable) {
if (!this.searchEl.value.length && this.selectedValue && this.selectedValue.length && this.clearable) {
let value = null;
if (this.multiple) {
value = [...this.selectedValue.slice(0, this.selectedValue.length - 1)]
@@ -939,7 +939,7 @@
};
const defaults = {
// delete
// backspace
8: e => this.maybeDeleteValue(),
// tab
9: e => this.onTab(),
+10
View File
@@ -69,6 +69,16 @@ describe('Custom Keydown Handlers', () => {
expect(spy).toHaveBeenCalledTimes(1);
});
it('will not emit input event if value has not changed with backspace', () => {
const Select = mountDefault();
Select.vm.$data._value = 'one';
Select.find({ ref: 'search' }).trigger('keydown.backspace');
expect(Select.emitted().input.length).toBe(1);
Select.find({ ref: 'search' }).trigger('keydown.backspace');
Select.find({ ref: 'search' }).trigger('keydown.backspace');
expect(Select.emitted().input.length).toBe(1);
});
});
});