Skip to content

Commit 2deab65

Browse files
authored
fix: do not fire custom-value-set on input blur or outside click (#8308)
1 parent 52219b4 commit 2deab65

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

packages/multi-select-combo-box/src/vaadin-multi-select-combo-box-internal-mixin.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ export const MultiSelectComboBoxInternalMixin = (superClass) =>
121121
return 'vaadin-multi-select-combo-box';
122122
}
123123

124+
constructor() {
125+
super();
126+
127+
this.addEventListener('custom-value-set', this.__onCustomValueSet.bind(this));
128+
}
129+
124130
/**
125131
* Override method inherited from the combo-box
126132
* to allow opening dropdown when readonly.
@@ -435,4 +441,13 @@ export const MultiSelectComboBoxInternalMixin = (superClass) =>
435441

436442
super.clearCache();
437443
}
444+
445+
/** @private */
446+
__onCustomValueSet(event) {
447+
// Prevent setting custom value on input blur or outside click,
448+
// so it can be only committed explicitly by pressing Enter.
449+
if (this._ignoreCommitValue) {
450+
event.stopImmediatePropagation();
451+
}
452+
}
438453
};

packages/multi-select-combo-box/test/basic.common.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from '@vaadin/chai-plugins';
22
import { fixtureSync, nextFrame, nextRender } from '@vaadin/testing-helpers';
3-
import { sendKeys } from '@web/test-runner-commands';
3+
import { resetMouse, sendKeys, sendMouse } from '@web/test-runner-commands';
44
import sinon from 'sinon';
55
import { isTouch } from '@vaadin/component-base/src/browser-utils.js';
66

@@ -331,6 +331,23 @@ describe('basic', () => {
331331
await sendKeys({ down: 'Enter' });
332332
expect(comboBox.selectedItems).to.deep.equal(['apple']);
333333
});
334+
335+
it('should not fire custom-value-set event when pressing Tab', async () => {
336+
const spy = sinon.spy();
337+
comboBox.addEventListener('custom-value-set', spy);
338+
await sendKeys({ type: 'pear' });
339+
await sendKeys({ down: 'Tab' });
340+
expect(spy.called).to.be.false;
341+
});
342+
343+
it('should not fire custom-value-set event on outside click', async () => {
344+
const spy = sinon.spy();
345+
comboBox.addEventListener('custom-value-set', spy);
346+
await sendKeys({ type: 'ap' });
347+
await sendMouse({ type: 'click', position: [200, 200] });
348+
await resetMouse();
349+
expect(spy.called).to.be.false;
350+
});
334351
});
335352

336353
describe('helper text', () => {

packages/multi-select-combo-box/test/selecting-items.common.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,21 @@ describe('selecting items', () => {
157157
expect(inputElement.value).to.equal('');
158158
});
159159

160+
it('should not select an item on outside click when it is focused', async () => {
161+
await sendKeys({ down: 'ArrowDown' });
162+
await sendKeys({ down: 'ArrowDown' });
163+
await sendMouse({ type: 'click', position: [200, 200] });
164+
await resetMouse();
165+
expect(comboBox.selectedItems).to.deep.equal([]);
166+
});
167+
168+
it('should not select an item on blur when it is focused', async () => {
169+
await sendKeys({ down: 'ArrowDown' });
170+
await sendKeys({ down: 'ArrowDown' });
171+
await sendKeys({ down: 'Tab' });
172+
expect(comboBox.selectedItems).to.deep.equal([]);
173+
});
174+
160175
it('should un-select item when using clear() method', () => {
161176
comboBox.selectedItems = ['orange'];
162177
comboBox.clear();

0 commit comments

Comments
 (0)