Skip to content

Commit 41ae485

Browse files
committed
fix: reset focused index when ignoring value commit
1 parent 685f561 commit 41ae485

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ export const MultiSelectComboBoxMixin = (superClass) =>
499499
// Do not commit focused item on not blur / outside click
500500
if (this._ignoreCommitValue) {
501501
this._inputElementValue = '';
502+
this._focusedIndex = -1;
502503
this._ignoreCommitValue = false;
503504
} else {
504505
this.__commitUserInput();

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@vaadin/chai-plugins';
2-
import { resetMouse, sendKeys, sendMouse } from '@vaadin/test-runner-commands';
2+
import { resetMouse, sendKeys, sendMouse, sendMouseToElement } from '@vaadin/test-runner-commands';
33
import { fixtureSync, keyboardEventFor, nextRender } from '@vaadin/testing-helpers';
44
import sinon from 'sinon';
55
import '../src/vaadin-multi-select-combo-box.js';
@@ -155,6 +155,32 @@ describe('selecting items', () => {
155155
expect(comboBox.selectedItems).to.deep.equal([]);
156156
});
157157

158+
it('should reset the item focused state when closing on outside click', async () => {
159+
await sendKeys({ press: 'ArrowDown' });
160+
await sendKeys({ press: 'ArrowDown' });
161+
await sendMouseToElement({ type: 'click', element: document.body });
162+
await resetMouse();
163+
164+
await sendKeys({ press: 'ArrowDown' });
165+
const item = getFirstItem(comboBox);
166+
expect(item.hasAttribute('focused')).to.be.false;
167+
});
168+
169+
it('should reset the item focused state when closing on blur', async () => {
170+
await sendKeys({ press: 'ArrowDown' });
171+
await sendKeys({ press: 'ArrowDown' });
172+
173+
// Blur the combo-box
174+
await sendKeys({ press: 'Shift+Tab' });
175+
176+
// Focus and re-open
177+
await sendKeys({ press: 'Tab' });
178+
179+
await sendKeys({ press: 'ArrowDown' });
180+
const item = getFirstItem(comboBox);
181+
expect(item.hasAttribute('focused')).to.be.false;
182+
});
183+
158184
it('should not select an item on blur when it is focused', async () => {
159185
await sendKeys({ down: 'ArrowDown' });
160186
await sendKeys({ down: 'ArrowDown' });

0 commit comments

Comments
 (0)