Skip to content

Commit 6a8a570

Browse files
authored
fix: do not unselect committed item on focusout (#3807)
1 parent c67871e commit 6a8a570

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,37 @@ class MultiSelectComboBoxInternal extends ComboBoxDataProviderMixin(ComboBoxMixi
179179
* @override
180180
*/
181181
_onFocusout(event) {
182+
// Disable combo-box logic that updates selectedItem
183+
// based on the overlay focused index on input blur
184+
this._ignoreCommitValue = true;
185+
182186
super._onFocusout(event);
183187

184188
if (this.readonly && !this._closeOnBlurIsPrevented) {
185189
this.close();
186190
}
187191
}
188192

193+
/**
194+
* Override method inherited from the combo-box
195+
* to not commit an already selected item again
196+
* on blur, which would result in un-selecting.
197+
* @protected
198+
* @override
199+
*/
200+
_detectAndDispatchChange() {
201+
if (this._ignoreCommitValue) {
202+
this._ignoreCommitValue = false;
203+
204+
// Reset internal combo-box state
205+
this.selectedItem = null;
206+
this._inputElementValue = '';
207+
return;
208+
}
209+
210+
super._detectAndDispatchChange();
211+
}
212+
189213
/**
190214
* @param {CustomEvent} event
191215
* @protected

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ describe('basic', () => {
197197
const item = document.querySelectorAll('vaadin-multi-select-combo-box-item')[1];
198198
expect(item.hasAttribute('focused')).to.be.true;
199199
});
200+
201+
it('should not unselect previously committed item on focusout', async () => {
202+
await sendKeys({ down: 'ArrowDown' });
203+
await sendKeys({ down: 'ArrowDown' });
204+
await sendKeys({ down: 'Enter' });
205+
await sendKeys({ down: 'Tab' });
206+
expect(comboBox.selectedItems).to.deep.equal(['apple']);
207+
});
200208
});
201209

202210
describe('pageSize', () => {

0 commit comments

Comments
 (0)