Skip to content

Commit 52219b4

Browse files
authored
fix: prevent unselecting already committed value on outside click (#8301)
1 parent f39f62d commit 52219b4

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,19 @@ export const MultiSelectComboBoxInternalMixin = (superClass) =>
341341
}
342342
}
343343

344+
/**
345+
* Override method inherited from the combo-box
346+
* to not commit an already selected item again
347+
* after closing overlay on outside click.
348+
* @protected
349+
* @override
350+
*/
351+
_onClosed() {
352+
this._ignoreCommitValue = true;
353+
354+
super._onClosed();
355+
}
356+
344357
/**
345358
* Override method inherited from the combo-box
346359
* to not commit an already selected item again
@@ -353,7 +366,7 @@ export const MultiSelectComboBoxInternalMixin = (superClass) =>
353366
this._ignoreCommitValue = false;
354367

355368
// Reset internal combo-box state
356-
this.selectedItem = null;
369+
this.clear();
357370
this._inputElementValue = '';
358371
return;
359372
}

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

Lines changed: 31 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, keyboardEventFor, 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 { getAllItems, getDataProvider, getFirstItem } from './helpers.js';
66

@@ -127,6 +127,36 @@ describe('selecting items', () => {
127127
expect(comboBox.selectedItems).to.deep.equal(['apple']);
128128
});
129129

130+
it('should not unselect previously committed item on outside click', async () => {
131+
await sendKeys({ down: 'ArrowDown' });
132+
await sendKeys({ down: 'ArrowDown' });
133+
await sendKeys({ down: 'Enter' });
134+
await sendMouse({ type: 'click', position: [200, 200] });
135+
await resetMouse();
136+
expect(comboBox.selectedItems).to.deep.equal(['apple']);
137+
});
138+
139+
it('should not unselect previously committed item on blur after outside click with allow custom value', async () => {
140+
comboBox.allowCustomValue = true;
141+
await sendKeys({ down: 'ArrowDown' });
142+
await sendKeys({ down: 'ArrowDown' });
143+
await sendKeys({ down: 'Enter' });
144+
await sendMouse({ type: 'click', position: [200, 200] });
145+
await resetMouse();
146+
await sendKeys({ down: 'Tab' });
147+
expect(comboBox.selectedItems).to.deep.equal(['apple']);
148+
});
149+
150+
it('should not set previously committed item to input on blur with allow custom value', async () => {
151+
comboBox.allowCustomValue = true;
152+
await sendKeys({ down: 'ArrowDown' });
153+
await sendKeys({ down: 'ArrowDown' });
154+
await sendKeys({ down: 'Enter' });
155+
await sendKeys({ down: 'Tab' });
156+
expect(comboBox.filter).to.equal('');
157+
expect(inputElement.value).to.equal('');
158+
});
159+
130160
it('should un-select item when using clear() method', () => {
131161
comboBox.selectedItems = ['orange'];
132162
comboBox.clear();

0 commit comments

Comments
 (0)