Skip to content

Commit

Permalink
fix: always update focus index on click
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki committed Dec 11, 2024
1 parent 993af45 commit a0bc08a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ export const SelectionMixin = (superClass) =>

const clickedRootElement = this.__getRootElementByContent(e.target);
if (clickedRootElement) {
this.__updateFocusIndex(clickedRootElement.__index);
this.__toggleSelection(clickedRootElement.__item);
}
}
Expand Down
17 changes: 17 additions & 0 deletions packages/virtual-list/test/virtual-list-selection.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,23 @@ describe('selection', () => {
expect(rendererSpy.getCalls().filter((call) => call.args[2].index === 0).length).to.equal(1);
});

it('should mark a previously focused element focused by clicking', async () => {
// Get a reference to the element representing the first item
const itemElement = getRenderedItem(0)!;
const firstItemElementTextContent = itemElement.textContent;
// Focus the first item by clicking
await click(itemElement);
// Scroll manually downwards
list.scrollTop = list.scrollHeight;
await nextFrame();
// Expect the same elemnt instance to now represent a different item due to virtualization
expect(itemElement.textContent).not.to.equal(firstItemElementTextContent);
// Click the same element again
await click(itemElement);
// Expect the element to be marked as focused
expect(itemElement.hasAttribute('focused')).to.be.true;
});

it('should select an item with keyboard', async () => {
expect(getRenderedItem(0)!.hasAttribute('selected')).to.be.false;
beforeButton.focus();
Expand Down

0 comments on commit a0bc08a

Please sign in to comment.