Skip to content

fix(body): preserve focus during virtual keyboard navigation - #818

Merged
fh1ch merged 1 commit into
mainfrom
fix/body-preserve-virtual-keyboard-focus
Aug 25, 2026
Merged

fix(body): preserve focus during virtual keyboard navigation#818
fh1ch merged 1 commit into
mainfrom
fix/body-preserve-virtual-keyboard-focus

Conversation

@spike-rabbit

@spike-rabbit spike-rabbit commented Aug 21, 2026

Copy link
Copy Markdown
Member

What kind of change does this PR introduce? (check one with "x")

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior? (You can also link to an open issue here)

Virtual keyboard navigation can lose focus when the adjacent row is outside the rendered range. Repeated key presses may advance through unloaded rows, and cell focus may not remain in the same column.

What is the new behavior?

Focus is tracked by logical row location and restored after virtualized rows render. Navigation waits for unloaded rows, uses absolute row indexes, preserves the focused cell column, and avoids native focus scrolling. Coverage includes grouped, virtualized, and lazy-loaded row navigation.

Does this PR introduce a breaking change? (check one with "x")

  • Yes
  • No

If this PR contains a breaking change, please describe the impact and migration path for existing applications: N/A

Other information:

@spike-rabbit
spike-rabbit requested a review from a team as a code owner August 21, 2026 07:22
@spike-rabbit
spike-rabbit force-pushed the fix/body-preserve-virtual-keyboard-focus branch from 0f6ff2a to 05535fa Compare August 21, 2026 07:28
@fh1ch
fh1ch requested a lite review from Copilot August 21, 2026 07:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes focus loss during keyboard navigation when using virtual scrolling by tracking the intended logical row position and restoring focus after the target row renders, while also preventing native focus-induced scrolling.

Changes:

  • Introduces an internal RowLocation type to represent logical row positions for focus navigation.
  • Updates DataTableBodyComponent keyboard focus handling to support virtualized/lazy-loaded rows (pending focus + scroll-to-index).
  • Adjusts row/cell focusing to use preventScroll and adds test coverage for virtual scroll navigation scenarios.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
projects/ngx-datatable/src/lib/types/internal.types.ts Adds RowLocation to model logical row positions for focus restoration.
projects/ngx-datatable/src/lib/components/body/keyboard-navigation.spec.ts Adds virtual scrolling keyboard navigation tests (down/up, column retention, unloaded rows).
projects/ngx-datatable/src/lib/components/body/body.component.ts Implements pending-focus navigation logic and uses absolute indexes to restore focus after virtualization.
projects/ngx-datatable/src/lib/components/body/body-row.component.ts Uses focus({ preventScroll: true }) and adds scrollIntoView() helper.
projects/ngx-datatable/src/lib/components/body/body-cell.component.ts Uses focus({ preventScroll: true }) to avoid native scroll jumps on focus.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@fh1ch fh1ch added the bug Something isn't working label Aug 25, 2026
@fh1ch
fh1ch force-pushed the fix/body-preserve-virtual-keyboard-focus branch from 05535fa to cb7ff66 Compare August 25, 2026 20:14
Base automatically changed from perf/initialize-datatable-dimensions to main August 25, 2026 20:25
Track row focus by logical location and restore it after virtualized rows render. Prevent repeated arrow presses from advancing through unloaded rows, and keep focused cells in the same rendered column.

Use absolute row indexes consistently, avoid native focus scrolling, and add coverage for grouped, virtualized, and lazy-loaded row navigation.
@fh1ch
fh1ch force-pushed the fix/body-preserve-virtual-keyboard-focus branch from cb7ff66 to 605218f Compare August 25, 2026 20:25

@fh1ch fh1ch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@spike-rabbit nice one, no findings from my end 🙇

LGTM 👍

@fh1ch
fh1ch added this pull request to the merge queue Aug 25, 2026
Merged via the queue into main with commit 8802273 Aug 25, 2026
9 checks passed
@fh1ch
fh1ch deleted the fix/body-preserve-virtual-keyboard-focus branch August 25, 2026 20:43
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.

3 participants