fix: align grouped sticky headers - #6472
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe sticky column-pinning example now supports grouped headers. It derives pinning styles from visible leaf columns, adds an ChangesGrouped header sticky pinning
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant HeaderCell
participant getHeaderPinningStyles
participant getCommonPinningStyles
HeaderCell->>getHeaderPinningStyles: pass grouped header
getHeaderPinningStyles->>getHeaderPinningStyles: find visible leaf columns
getHeaderPinningStyles->>getCommonPinningStyles: pass leaf boundaries and pin position
getCommonPinningStyles-->>HeaderCell: return sticky styles
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
MILLERMARRU
left a comment
There was a problem hiding this comment.
This example previously had no grouped columns at all, firstName and lastName were flat top-level accessors, so there was actually no way to exercise sticky positioning for a group header before this PR. Wrapping them in an info group is what exposes the bug in the first place, getCommonPinningStyles(column) was being called with the group's own column, whose getIsPinned/getStart/getAfter don't reflect what its leaf columns are actually doing.
I checked header_getSize in table-core to confirm header.getSize() on a group header already sums its leaf columns (sumHeaderSize), so using it directly as width for the group is correct and explains why the tests expect the Info header to be ~360px (180+180) rather than the single-column 180.
The "every leaf column must share the same pinned side" check in getHeaderPinningStyles is the right call for deciding sticky vs relative. The first test nails exactly why: pin only First Name to start while Last Name stays unpinned, and since pinning to start doesn't reorder columns when the pinned one is already first, TanStack still renders Info as one merged header cell, just now with mixed-pinned leaves underneath. Without the "all leaves agree" check, that merged cell would likely have inherited a stale or partial sticky style. The test asserting position: relative in that exact intermediate state is a good regression guard, and the second test showing Info splits into two separate header cells once First Name is pinned to end (because pinning to end physically reorders it away from Last Name) is a nice demonstration that the split itself is TanStack's own header-group logic doing its job, not something this PR has to handle manually.
Using firstLeafColumn.getStart('start') and lastLeafColumn.getAfter('end') instead of the group column's own offsets is correct since a group column has no size/position of its own outside of what its leaves contribute, and the boundingBox assertions comparing the sticky header's x against the actual leaf header's x are a good way to catch an off-by-one-column offset that a snapshot-only test would miss.
Only thing I'd note is this all lives in an example, so it's more "here's the pattern to copy" than covered by table-core's own test suite, but for a docs example that's the right place for this logic to live since it's inherently presentational.
🎯 Changes
Fix grouped sticky headers in the React column pinning example.
Grouped headers now derive their sticky side, offsets, width, and boundary shadow from the leaf columns rendered by the current header segment. This keeps mixed partial-pinning segments relative and aligns fully pinned groups when other pinned columns precede or follow them.
Add Playwright coverage for partial group pinning and non-zero start/end offsets.
Fixes #5397
✅ Checklist
pnpm test:pr.Summary by CodeRabbit
New Features
Tests