Skip to content

feat: add arrow key navigation to GridView#509

Merged
willeastcott merged 2 commits into
mainfrom
feat/gridview-arrow-key-navigation
Feb 26, 2026
Merged

feat: add arrow key navigation to GridView#509
willeastcott merged 2 commits into
mainfrom
feat/gridview-arrow-key-navigation

Conversation

@willeastcott

@willeastcott willeastcott commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add keyboard navigation to GridView so that arrow keys move selection between items when a GridViewItem has focus
  • ArrowLeft/Right navigate between adjacent siblings (or between adjacent items in vertical mode)
  • ArrowUp/Down navigate between rows, preserving column position (or between adjacent items in vertical mode)
  • If the target row is shorter than the current row, selection lands on the last item in that row
  • Uses event delegation on the GridView container DOM for efficiency (no per-item listeners needed)
  • Calls preventDefault()/stopPropagation() on handled keys to prevent parent handlers from consuming them

Motivation

When a GridViewItem has focus (e.g. after clicking an asset in the PlayCanvas Editor's grid view), arrow key events bubble up to window unhandled. The Editor's camera-fly system catches them and moves the viewport camera, which is unexpected. The TreeView and Table components already handle arrow keys and stop propagation; GridView was the only component missing this.

Test plan

  • Lint passes
  • All existing tests pass
  • Manual: create a GridView with items, click one, press arrow keys to navigate
  • Manual: verify Up/Down correctly jump between rows and preserve column
  • Manual: verify navigation stops at grid boundaries (no wrap-around)
  • Manual: verify short last row handles ArrowDown gracefully (lands on last item)

Add keyboard navigation support to GridView so that arrow keys move selection between items when a GridViewItem has focus. This prevents arrow key events from bubbling up to parent handlers (e.g. viewport camera controls in the Editor).

- ArrowLeft/Right navigate between adjacent siblings

- ArrowUp/Down navigate between rows, preserving column position

- Handles both horizontal (default) and vertical grid layouts

- Uses event delegation on the GridView container for efficiency

- Properly calls preventDefault/stopPropagation to consume handled keys

Made-with: Cursor

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 adds keyboard navigation support to the GridView component, allowing users to navigate between grid items using arrow keys. The implementation prevents arrow key events from bubbling up to parent handlers (like the camera-fly system in the PlayCanvas Editor), matching the behavior of TreeView and Table components.

Changes:

  • Added event delegation-based keyboard handler to GridView for arrow key navigation
  • Implemented _findItemInAdjacentRow method to navigate between rows/columns while preserving position
  • Added _selectSingleItem helper method to handle single-item selection during navigation

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

Comment thread src/components/GridView/index.ts Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@willeastcott willeastcott merged commit 186a0c6 into main Feb 26, 2026
5 checks passed
@willeastcott willeastcott deleted the feat/gridview-arrow-key-navigation branch February 26, 2026 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants