Repository navigation
Remove unnecessary | undefined from types - #4219
Merged
Merged
Conversation
`onCellKeyDown` is only called when the active position is in the viewport, so `row` is always defined in ACTIVE mode. `column` stays possibly undefined because TreeDataGrid can activate a whole row. `PositionChangeArgs` keeps both: `row` is undefined on header and summary rows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4219 +/- ##
=======================================
Coverage 98.36% 98.36%
=======================================
Files 45 45
Lines 1955 1955
Branches 727 727
=======================================
Hits 1923 1923
Misses 32 32
🚀 New features to boost your workflow:
|
`bottomSummaryRowsCount > 0` already implies `bottomSummaryRows != null`. `onCellKeyDown` is never called on the header row or when there are no rows, so the `rowIdx === -1` and `rows.length === 0` branches in the CellNavigation demo were dead code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nstepien
marked this pull request as ready for review
October 21, 2026 23:55
nstepien
added a commit
that referenced
this pull request
Oct 22, 2026
) Found while working on #4219. In a grid with column groups and bottom summary rows, moving the active cell into a column group header row called the user's `colSpan` with `{ type: 'SUMMARY', row: undefined }`. `getCellColSpan` checks for the main header row, then top summary rows, then data rows. Any other `rowIdx` fell through to the bottom summary rows branch, and that included column group header rows above the main header row. So `bottomSummaryRows[rowIdx - rows.length]` read a negative index. A `colSpan` that reads `args.row` for summary rows would throw, and one that returns a span for summary rows would move the active cell to the wrong column. The bottom summary rows branch now also requires `rowIdx >= rows.length`. Column group header rows fall through to `return undefined`, which is what we want because column group header cells don't use `colSpan`. The new test failed in Chromium, Firefox, and WebKit before the fix. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
nstepien
added a commit
that referenced
this pull request
Oct 29, 2026
…h group rows, and export `isGroupRow` (#4265) `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 ```diff - 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](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Narrows
ActiveCellKeyDownArgs.rowfromTRow | undefinedtoTRow. The grid only callsonCellKeyDownwhen the active position is in the viewport (activePositionIsInViewport), sorows[rowIdx]is always defined. The type wasTRowuntil #3979 widened it.The other fields that looked like candidates still need
| undefined:ActiveCellKeyDownArgs.columnandPositionChangeArgs.column:undefinedwhen aTreeDataGridrow is active (idx: -1).TreeDataGrid's ownhandleKeyDowndepends on this withcolumn?.idx ?? -1.PositionChangeArgs.row:undefinedon header and summary rows.events.test.tsxassertsrow: undefinedfor the header row.These fields type-check without
| undefinedonly becausenoUncheckedIndexedAccessis off, sorows[i]andcolumns[i]have typeR. I added a doc comment toActiveCellKeyDownArgs.column, matchingPositionChangeArgs, so it's clear whyundefinedis there.Internal cleanups:
scrollIntoView(element):Maybe<Element>→Element | null. No caller passesundefined.Cell'shandleMouseEvent: theeventHandlerparameter is no longer optional. Every caller passes it, andCellMouseEventHandleralready includesundefined.Conditions that can never be true:
DataGrid: removedbottomSummaryRows != nullfrom the bottom summary shadow.bottomSummaryRowsCountisbottomSummaryRows?.length ?? 0, sobottomSummaryRowsCount > 0already implies it.CellNavigationdemo: removed therowIdx === -1androws.length === 0branches.onCellKeyDownnever fires on the header row or when there are no rows, so these branches never ran.I checked every other
| undefined,Maybe<>, and optional parameter insrc/,website/, andtest/. Each one can actually beundefinedornull, or is a user-facing input prop.typescript/no-unnecessary-condition(type-aware) already catches conditions that are unnecessary by type, so I only looked for ones that are unnecessary at runtime.🤖 Generated with Claude Code