Skip to content

fix: remove auto-select on focusin from GridView#519

Merged
willeastcott merged 1 commit intomainfrom
fix/gridview-focusin-auto-select
Mar 4, 2026
Merged

fix: remove auto-select on focusin from GridView#519
willeastcott merged 1 commit intomainfrom
fix/gridview-focusin-auto-select

Conversation

@willeastcott
Copy link
Contributor

@willeastcott willeastcott commented Mar 4, 2026

Summary

Follow-up to #518 — applies the same _onFocusIn fix to GridView that was applied to TreeView.

  • Simplifies GridView._onFocusIn to only update the roving tabindex active item (_setActiveItem), removing the auto-selection logic that checked :focus-visible and modified selection state on focus-in
  • Updates the corresponding unit test to assert that focusing an item does not auto-select it

Motivation

The GridView._onFocusIn handler contained the same auto-selection logic that caused the race condition fixed in TreeView by #518. External consumers (like the PlayCanvas Editor) manage selection state themselves, so having focusin silently select items creates conflicts and visual desync between the component's selection state and the application's selection state.

Test Plan

  • All 50 PCUI unit tests pass (npm test)
  • Manually verify GridView selection in the Editor's asset panel — clicking to select/deselect assets should behave correctly with no lingering selections

@willeastcott willeastcott requested a review from Copilot March 4, 2026 10:22
@willeastcott willeastcott self-assigned this Mar 4, 2026
@willeastcott willeastcott added the bug Something isn't working label Mar 4, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes the auto-select-on-focus behavior from GridView._onFocusIn, aligning GridView with the earlier TreeView fix from #518 so external consumers can fully control selection state without focus-driven side effects.

Changes:

  • Simplifies GridView._onFocusIn to only update the roving-tabindex active item (_setActiveItem), removing selection mutation on focus-in.
  • Updates the GridView unit test to assert that focusing an item does not auto-select it.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/components/GridView/index.ts Removes focus-in auto-selection logic; focus-in now only updates the active (tabIndex=0) item.
test/components/gridview.mjs Updates the test expectation for focus-in behavior to ensure focus does not modify selection state.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines 178 to +182
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);
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.
@willeastcott willeastcott merged commit e6b77dc into main Mar 4, 2026
9 checks passed
@willeastcott willeastcott deleted the fix/gridview-focusin-auto-select branch March 4, 2026 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants