Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ export const MultiSelectComboBoxInternalMixin = (superClass) =>
return 'vaadin-multi-select-combo-box';
}

constructor() {
super();

this.addEventListener('custom-value-set', this.__onCustomValueSet.bind(this));
}

/**
* Override method inherited from the combo-box
* to allow opening dropdown when readonly.
Expand Down Expand Up @@ -435,4 +441,13 @@ export const MultiSelectComboBoxInternalMixin = (superClass) =>

super.clearCache();
}

/** @private */
__onCustomValueSet(event) {
// Prevent setting custom value on input blur or outside click,
// so it can be only committed explicitly by pressing Enter.
if (this._ignoreCommitValue) {
event.stopImmediatePropagation();
}
}
};
19 changes: 18 additions & 1 deletion packages/multi-select-combo-box/test/basic.common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from '@vaadin/chai-plugins';
import { fixtureSync, nextFrame, nextRender } from '@vaadin/testing-helpers';
import { sendKeys } from '@web/test-runner-commands';
import { resetMouse, sendKeys, sendMouse } from '@web/test-runner-commands';
import sinon from 'sinon';
import { isTouch } from '@vaadin/component-base/src/browser-utils.js';

Expand Down Expand Up @@ -331,6 +331,23 @@ describe('basic', () => {
await sendKeys({ down: 'Enter' });
expect(comboBox.selectedItems).to.deep.equal(['apple']);
});

it('should not fire custom-value-set event when pressing Tab', async () => {
const spy = sinon.spy();
comboBox.addEventListener('custom-value-set', spy);
await sendKeys({ type: 'pear' });
await sendKeys({ down: 'Tab' });
expect(spy.called).to.be.false;
});

it('should not fire custom-value-set event on outside click', async () => {
const spy = sinon.spy();
comboBox.addEventListener('custom-value-set', spy);
await sendKeys({ type: 'ap' });
await sendMouse({ type: 'click', position: [200, 200] });
await resetMouse();
expect(spy.called).to.be.false;
});
});

describe('helper text', () => {
Expand Down
15 changes: 15 additions & 0 deletions packages/multi-select-combo-box/test/selecting-items.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,21 @@ describe('selecting items', () => {
expect(inputElement.value).to.equal('');
});

it('should not select an item on outside click when it is focused', async () => {
await sendKeys({ down: 'ArrowDown' });
await sendKeys({ down: 'ArrowDown' });
await sendMouse({ type: 'click', position: [200, 200] });
await resetMouse();
expect(comboBox.selectedItems).to.deep.equal([]);
});

it('should not select an item on blur when it is focused', async () => {
await sendKeys({ down: 'ArrowDown' });
await sendKeys({ down: 'ArrowDown' });
await sendKeys({ down: 'Tab' });
expect(comboBox.selectedItems).to.deep.equal([]);
});

it('should un-select item when using clear() method', () => {
comboBox.selectedItems = ['orange'];
comboBox.clear();
Expand Down
Loading