Skip to content

TreeDataGrid: type onCellKeyDown and onActivePositionChange with group rows, and export isGroupRow - #4265

Merged
nstepien merged 2 commits into
mainfrom
breaking/tree-group-rows-in-callbacks
Oct 29, 2026
Merged

nstepien merged 2 commits into
mainfrom
breaking/tree-group-rows-in-callbacks

Conversation

@nstepien

@nstepien nstepien commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

TreeDataGrid passes its group rows to DataGrid as R, so when a group row, or a cell of one, is active, onCellKeyDown and onActivePositionChange receive a GroupRow typed as R: a property access like args.row.name.toUpperCase() type-checks and throws at runtime. Their row is now typed R | GroupRow<R>, and isGroupRow is exported so handlers can narrow it. Like #4219, this makes the types say what happens.

Builds on #4264.

Breaking change

- function onCellKeyDown(args: CellKeyDownArgs<Row>, event: CellKeyboardEvent) {
-   console.log(args.row.name);
+ function onCellKeyDown(args: TreeCellKeyDownArgs<Row>, event: CellKeyboardEvent) {
+   if (isGroupRow(args.row)) return;
+   console.log(args.row.name);
  }

Affects TreeDataGrid's onCellKeyDown and onActivePositionChange handlers: their row is typed R | GroupRow<R>, which is what the grid passed all along when a group row was active. isGroupRow is exported to narrow it. DataGrid handlers are unchanged.

Changes

  • CellKeyDownArgs and PositionChangeArgs get a third type parameter, TActiveRow, which defaults to TRow, so DataGrid handler types are unchanged. It only applies to the ACTIVE variant of CellKeyDownArgs: EditCell is only rendered through Row, never through GroupedRow, so EDIT args never carry a group row.
  • New exported aliases, TreeCellKeyDownArgs<R, SR> and TreePositionChangeArgs<R, SR>, keep handlers short. The third type parameter stays public and is documented next to them.
  • TreeDataGridProps omits the two inherited props and redeclares them with the aliases; TreeDataGrid's own handleKeyDown uses TreeCellKeyDownArgs. Passing them on to DataGrid type-checks because function parameters are contravariant.
  • isGroupRow is exported from TreeDataGrid.tsx, where it stays with its WeakSet: DataGrid doesn't use it, so exporting it from there creates no import cycle. If the group-row edit-mode bug below gets fixed in DataGrid, that PR can move both to a shared module.
  • The rows as R[] cast stays, and its TODO comment now explains which callbacks receive group rows.
  • README: isGroupRow under "Other", the aliases and the third type parameter under "Types", onCellKeyDown and onActivePositionChange under TreeDataGridProps, and a "Group rows in callbacks" paragraph with an example under <TreeDataGrid />. The CellKeyDownArgs and PositionChangeArgs headings gain TActiveRow, so their anchors changed and the links to them are updated.
  • Re-verified that the other callbacks never receive group rows: the cell mouse events (group cells don't fire them), rowClass (not applied to group rows), onCellCopy and onCellPaste (filtered), renderers.renderRow and renderCell (wrapped), rowHeight (RowHeightArgs), and onRowsChange (indexes mapped back).

Follow-ups

  • Typing on a cell of a group row in a column with renderEditCell sets mode: 'EDIT' with the group row; no editor renders, and the arrow keys stop working until a click. That fix gets its own PR.

Verification

vp run ci passes on the top of the stack (#4272). Added a browser test that activates a group row, then a cell of it, then a cell of a regular row, and asserts which rows onCellKeyDown and onActivePositionChange received, using isGroupRow. A consumer type-check of the built lib/index.d.ts, with and without exactOptionalPropertyTypes, uses TreeCellKeyDownArgs, TreePositionChangeArgs, isGroupRow, GroupRow, expandedGroupIds, and renderGroupCell.

🤖 Generated with Claude Code

@nstepien
nstepien added this pull request to stack #4266 October 27, 2026 19:50
@nstepien nstepien changed the title TreeDataGrid: type onCellKeyDown and onActivePositionChange with group rows, and export isGroupRow TreeDataGrid: type onCellKeyDown and onActivePositionChange with group rows, and export isGroupRow Oct 27, 2026
@codecov-commenter

codecov-commenter commented Oct 27, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.27%. Comparing base (4f19b31) to head (66866bf).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4265   +/-   ##
=======================================
  Coverage   99.27%   99.27%           
=======================================
  Files          44       44           
  Lines        2213     2213           
  Branches      971      971           
=======================================
  Hits         2197     2197           
  Misses         16       16           
Files with missing lines Coverage Δ
src/TreeDataGrid.tsx 98.66% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nstepien
nstepien force-pushed the breaking/tree-group-rows-in-callbacks branch from 3640afb to 6bd1d78 Compare October 28, 2026 22:52
@nstepien
nstepien force-pushed the breaking/tree-group-rows-in-callbacks branch 3 times, most recently from fb6fdd3 to 21259a2 Compare October 29, 2026 02:18
Base automatically changed from breaking/group-cell-props-row to main October 29, 2026 02:20
…p rows, and export isGroupRow

`TreeDataGrid` passes group rows to `onCellKeyDown` and
`onActivePositionChange` when a group row, or a cell of one, is active, but
their `row` was typed as `R`. `CellKeyDownArgs` and `PositionChangeArgs`
get a third type parameter for the active row's type, `TreeDataGridProps`
types the two callbacks with the new `TreeCellKeyDownArgs` and
`TreePositionChangeArgs` aliases, and `isGroupRow` is exported to narrow
the row. `DataGrid` handlers are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nstepien
nstepien force-pushed the breaking/tree-group-rows-in-callbacks branch from 21259a2 to 1043e46 Compare October 29, 2026 02:20
The runtime test passes handlers typed with `TreeCellKeyDownArgs` and `TreePositionChangeArgs` to the grid, and narrows their rows with `isGroupRow`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nstepien
nstepien marked this pull request as ready for review October 29, 2026 02:44
@nstepien
nstepien merged commit db782a8 into main Oct 29, 2026
6 checks passed
@nstepien
nstepien deleted the breaking/tree-group-rows-in-callbacks branch October 29, 2026 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants