Repository navigation
refactor: share sticky header internals between Table and Container - #5212
gethinwebster wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5212 +/- ##
==========================================
+ Coverage 97.75% 97.82% +0.06%
==========================================
Files 1003 1006 +3
Lines 32534 32602 +68
Branches 12082 12111 +29
==========================================
+ Hits 31805 31893 +88
+ Misses 684 667 -17
+ Partials 45 42 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
8bb6cd6 to
afb22d4
Compare
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the shared sticky-header extraction.
No open issues 🎉
What changed in this PR
Extracts sticky-header internals into a shared module for Table, Container, and Cards, preparing for reuse by atomic table components without changing public APIs.
Changes:
- Centralizes sticky positioning, stuck-state tracking, header synchronization, scrolling helpers, and scrollbar styles.
- Extracts cell resize observation and refreshes observed cells after each render to handle remounts.
- Adds resize-observer unit tests and relocates sticky-offset tests.
| File | Description |
|---|---|
src/table/use-sticky-header.ts |
Delegates to shared header synchronization. |
src/table/use-column-widths.tsx |
Uses the shared cell resize observer. |
src/table/styles.scss |
Uses the shared hidden-scrollbar mixin. |
src/internal/components/sticky-header/use-sticky-position.ts |
Houses sticky positioning and offset calculation. |
src/internal/components/sticky-header/use-sticky-header-sync.ts |
Houses header overlap and focus-scrolling logic. |
src/internal/components/sticky-header/use-header-stuck.ts |
Extracts stuck-state tracking. |
src/internal/components/sticky-header/use-cells-resize-observer.ts |
Tracks cell replacements and resize notifications. |
src/internal/components/sticky-header/sticky-scrolling.ts |
Relocates scrolling helpers and removes stale parameter documentation. |
src/internal/components/sticky-header/mixins.scss |
Defines shared hidden-scrollbar styles. |
src/internal/components/sticky-header/__tests__/use-cells-resize-observer.test.tsx |
Tests resizing, replacement cells, callback updates, and cleanup. |
src/internal/components/sticky-header/__tests__/sticky-offset.test.ts |
Relocates offset tests and updates imports. |
src/container/use-sticky-header.ts |
Delegates to shared sticky positioning. |
src/cards/index.tsx |
Imports scrolling helpers from the shared module. |
Review effort: Balanced
afb22d4 to
b701f16
Compare
| __additionalOffset?: boolean; | ||
| } | ||
|
|
||
| export function computeOffset({ |
There was a problem hiding this comment.
Nit: why is this function exported? It doesn't seem to be used anywhere else
There was a problem hiding this comment.
good catch, it was only used in tests. I've un-exported it and updated tests
| useLayoutEffect(() => { | ||
| syncColumnHeaderWidths(); | ||
| ) => | ||
| useStickyHeaderSync({ |
There was a problem hiding this comment.
This part of the refactor does not look very necessary. useStickyHeader now only calls useStickyHeaderSync, and useStickyHeaderSync does not seem to be called anywhere else.
There was a problem hiding this comment.
updated by renaming this and importing it directly rather than having this file that just imports and re-exports it. this hook will also be imported in the atomic table components when we implement sticky header there (that's what this PR is unblocking)
b701f16 to
9d1b40a
Compare
Description
Moves the sticky header logic that Table and Container use into one shared internal module,
src/internal/components/sticky-header/. This lets the table components (TableRootand friends) reuse it for their sticky header in a follow-up PR, instead of having a second copy.What moves, with no change to public APIs:
use-sticky-header-copy.ts,sticky-scrolling.ts).use-cells-resize-observer.ts).use-sticky-position.ts,use-header-stuck.ts).Table, Container and Cards now call the shared code and are otherwise unchanged. One small difference: Table used to re-collect the header cells it watches only when the visible columns changed. It now re-collects them after each render, so it also picks up cells that remount for other reasons.
Related links, issue #, if available: n/a
How has this been tested?
scrollToTopandscrollToRow, which had no coverage in the existing Table either.useStickyPositionhook and check thetopit applies, so they also cover the scrolling-parent and app layout<main>checks.Review checklist
The following items are to be evaluated by the author(s) and the reviewer(s).
Correctness
CONTRIBUTING.md.CONTRIBUTING.md.Security
checkSafeUrlfunction.Testing
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.