Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions src/components/GridView/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,7 @@ class GridView extends Container {
let node = evt.target as HTMLElement;
while (node && node !== this.dom) {
if (node.ui instanceof GridViewItem) {
const item = node.ui;
this._setActiveItem(item);

const focused = evt.target as HTMLElement;
if (focused.matches(':focus-visible')) {
const related = evt.relatedTarget as HTMLElement;
if (!related || !this.dom.contains(related)) {
if (!item.selected) {
let i = this._selected.length;
while (i--) {
if (this._selected[i] && this._selected[i] !== item) {
this._selected[i].selected = false;
}
}
item.selected = true;
}
}
}
this._setActiveItem(node.ui);
return;
}
node = node.parentElement;
Expand Down
10 changes: 2 additions & 8 deletions test/components/gridview.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,15 @@ describe('GridView', () => {
gridView.filterAsync();
});

it('should select the item when focus enters from outside via keyboard', () => {
it('should not select the item when focus enters from outside via keyboard', () => {
const { gridView, item1 } = buildGrid();
document.body.appendChild(gridView.dom);

strictEqual(item1.selected, false);

// Simulate keyboard Tab-in by focusing and dispatching focusin.
// jsdom's :focus-visible heuristic is unreliable across tests,
// so we stub matches() to return true for the duration.
const origMatches = item1.dom.matches.bind(item1.dom);
item1.dom.matches = (sel) => sel === ':focus-visible' ? true : origMatches(sel);
item1.focus();
item1.dom.matches = origMatches;

strictEqual(item1.selected, true);
strictEqual(item1.selected, false);
Comment on lines 178 to +182
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This updated test no longer forces :focus-visible (or a focusin-from-outside scenario), so it will likely pass even if the old auto-select-on-focus logic were still present (jsdom often reports matches(':focus-visible') === false). To make this regression-proof, keep stubbing matches(':focus-visible') to true (or explicitly dispatch a focusin with an external relatedTarget) and still assert that selected remains false.

Copilot uses AI. Check for mistakes.

document.body.removeChild(gridView.dom);
});
Expand Down