Skip to content

Commit a0bc08a

Browse files
committed
fix: always update focus index on click
1 parent 993af45 commit a0bc08a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

packages/virtual-list/src/vaadin-virtual-list-selection-mixin.js

+1
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ export const SelectionMixin = (superClass) =>
386386

387387
const clickedRootElement = this.__getRootElementByContent(e.target);
388388
if (clickedRootElement) {
389+
this.__updateFocusIndex(clickedRootElement.__index);
389390
this.__toggleSelection(clickedRootElement.__item);
390391
}
391392
}

packages/virtual-list/test/virtual-list-selection.common.ts

+17
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,23 @@ describe('selection', () => {
191191
expect(rendererSpy.getCalls().filter((call) => call.args[2].index === 0).length).to.equal(1);
192192
});
193193

194+
it('should mark a previously focused element focused by clicking', async () => {
195+
// Get a reference to the element representing the first item
196+
const itemElement = getRenderedItem(0)!;
197+
const firstItemElementTextContent = itemElement.textContent;
198+
// Focus the first item by clicking
199+
await click(itemElement);
200+
// Scroll manually downwards
201+
list.scrollTop = list.scrollHeight;
202+
await nextFrame();
203+
// Expect the same elemnt instance to now represent a different item due to virtualization
204+
expect(itemElement.textContent).not.to.equal(firstItemElementTextContent);
205+
// Click the same element again
206+
await click(itemElement);
207+
// Expect the element to be marked as focused
208+
expect(itemElement.hasAttribute('focused')).to.be.true;
209+
});
210+
194211
it('should select an item with keyboard', async () => {
195212
expect(getRenderedItem(0)!.hasAttribute('selected')).to.be.false;
196213
beforeButton.focus();

0 commit comments

Comments
 (0)