An open source design system that's fully customizable and agent ready
TypeScript
fix(Table): two defects surfaced by frozen columns and grouped rows (#5454)
Ernestf54274989520
diff --git a/.changeset/grouped-rows-pinned-heading.md b/.changeset/grouped-rows-pinned-heading.mdnew file mode 100644index 0000000000..635ee53237--- /dev/null+++ b/.changeset/grouped-rows-pinned-heading.md@@ -0,0 +1,21 @@+---+'@astryxdesign/core': patch+---++[fix] `useTableGroupedRows`: the section heading stays on screen when the table+scrolls sideways++A group header is one cell spanning every column, so on a table scrolled+sideways its chevron and label slid out of view while the columns they named+stayed pinned — leaving unlabelled grey bands and no way to collapse a section+without scrolling back. The heading now sticks to the table's start edge.++The cell's start gutter moves onto the heading itself so that it travels with+it; left on the cell, the heading would sit one gutter in at rest and jump+flush the moment it stuck.++This was previously only patchable halfway from userland: `renderGroupHeader`+can pin its own content, but the chevron is the plugin's and sits outside it,+so the two would come apart.++@ernesttiendiff --git a/.changeset/table-selection-sticky-overlay.md b/.changeset/table-selection-sticky-overlay.mdnew file mode 100644index 0000000000..b14f303fc7--- /dev/null+++ b/.changeset/table-selection-sticky-overlay.md@@ -0,0 +1,18 @@+---+'@astryxdesign/core': patch+---++[fix] `useTableSelection`: the checked-row wash now survives a frozen column++A sticky cell paints an opaque background of its own so scrolled content can't+show through, then replays the row's fill on a `::before` layer from+`--table-row-overlay`. `TableRow` publishes that variable alongside every+background it sets, which is how striping and hover carry across the freeze+line. Selection did not: it wrote `backgroundColor` on the `<tr>` and stopped+there, so a checked row lost its accent wash under every pinned column — the+row read as selected on the scrollable side and unselected on the frozen one.++The wash and the variable are now written together, and withdrawn together+when a row is unchecked or `hasRowHighlight` is turned off.++@ernesttiendiff --git a/packages/core/src/Table/plugins/groupedRows/useTableGroupedRows.tsx b/packages/core/src/Table/plugins/groupedRows/useTableGroupedRows.tsxindex 5edb1a1194..7a3004bf74 100644--- a/packages/core/src/Table/plugins/groupedRows/useTableGroupedRows.tsx+++ b/packages/core/src/Table/plugins/groupedRows/useTableGroupedRows.tsx@@ -126,15 +126,31 @@ const styles = stylex.create({},headerCell: {paddingBlock: spacingVars['--spacing-2'],- // No inline start padding so the chevron aligns with the table's leading- // edge (Ernest review #1).- paddingInlineStart: spacingVars['--spacing-1'],+ // The start gutter lives on headerInner instead, so that it travels with+ // the heading when the heading pins. Left here, the heading would sit one+ // gutter in at rest and jump flush the moment it stuck.+ paddingInlineStart: 0,paddingInlineEnd: spacingVars['--spacing-3'],},+ // The cell spans every column, so on a table scrolled sideways the heading+ // would slide out of view while the columns it names stay pinned. Sticking+ // the inner span to the start edge keeps the chevron and the label together+ // and on screen.headerInner: {display: 'flex',alignItems: 'center',gap: spacingVars['--spacing-1'],+ insetInlineStart: 0,+ position: 'sticky',+ // No inline start padding on the cell, so the chevron aligns with the+ // table's leading edge (Ernest review #1).+ paddingInlineStart: spacingVars['--spacing-1'],+ },+ // Applied alongside headerInner when using the built-in default heading.+ // A custom `renderGroupHeader` may need the full column width, so the+ // shrink-wrap is opt-in rather than unconditional.+ headerInnerFitContent: {+ width: 'fit-content',},// Standalone chevron button with no heavy chrome (transparent, borderless,// zero padding) so the icon sits flush with the start of the table@@ -222,6 +238,32 @@ const styles = stylex.create({* plugins={{grouped: grouped.plugin}}* />;* ```+ *+ * ## Pairing with pagination+ *+ * Grouping runs on the rows it is handed, so the order is filter, sort, slice,+ * then group. Sort by the group key first and the reader's own keys second —+ * the same `ORDER BY group, sort` a backend would run. That keeps a section's+ * rows contiguous in the result set, so pages fill sections in order and new+ * rows always land at the bottom of the table. Slice a differently-ordered+ * list and every page holds a scatter of sections instead, so loading more+ * splices rows into the middle and new headings appear above the fold.+ *+ * @example+ * ```+ * const ordered = useMemo(+ * () => [...filtered].sort((a, b) => byTeam(a, b) || bySortKeys(a, b)),+ * [filtered, sortKeys],+ * );+ * const page = ordered.slice(0, loadedCount);+ *+ * const grouped = useTableGroupedRows({+ * data: page,+ * groupBy: r => r.team,+ * collapsedGroups,+ * onToggleGroup,+ * });+ * ```*/export function useTableGroupedRows<T extends Record<string, unknown>>(config: UseTableGroupedRowsConfig<T>,@@ -342,7 +384,11 @@ export function useTableGroupedRows<T extends Record<string, unknown>>(// to the actual number of columns, so the header always spans the// full width without the plugin knowing the column count.<td colSpan={999} {...stylex.props(styles.headerCell)}>- <span {...stylex.props(styles.headerInner)}>+ <span+ {...stylex.props(+ styles.headerInner,+ !renderGroupHeader && styles.headerInnerFitContent,+ )}>{/* Standalone chevron button, flush with the table's startedge (no heavy button chrome) — the keyboard control. */}<buttondiff --git a/packages/core/src/Table/plugins/selection/useTableSelection.test.tsx b/packages/core/src/Table/plugins/selection/useTableSelection.test.tsxindex fef04d2828..63a4cc0174 100644--- a/packages/core/src/Table/plugins/selection/useTableSelection.test.tsx+++ b/packages/core/src/Table/plugins/selection/useTableSelection.test.tsx@@ -285,6 +285,68 @@ describe('useTableSelection', () => {'aria-selected',);});++ // A pinned cell paints over the row, then replays whatever the row+ // published as --table-row-overlay. Without the variable the wash simply+ // stops at the freeze line, so it has to track the background exactly.+ describe('--table-row-overlay', () => {+ const readOverlay = (row: HTMLElement) =>+ row.style.getPropertyValue('--table-row-overlay');++ it('publishes the wash so pinned cells can replay it', async () => {+ const user = userEvent.setup();+ render(<SelectionTable />);++ await user.click(screen.getAllByLabelText('Select row')[0]);++ expect(readOverlay(screen.getAllByRole('row')[1])).toBe(+ selectedBgColor,+ );+ });++ it('publishes nothing when the row is not painted', async () => {+ const user = userEvent.setup();+ render(<SelectionTable hasRowHighlight={false} />);++ await user.click(screen.getAllByLabelText('Select row')[0]);++ expect(readOverlay(screen.getAllByRole('row')[1])).toBe('');+ });++ it('withdraws the variable when a row is unchecked', async () => {+ const user = userEvent.setup();+ render(<SelectionTable />);++ const checkbox = screen.getAllByLabelText('Select row')[0];+ await user.click(checkbox);+ await user.click(checkbox);++ expect(readOverlay(screen.getAllByRole('row')[1])).toBe('');+ });++ it('tracks the background when the flag flips', async () => {+ const user = userEvent.setup();+ const {rerender} = render(<SelectionTable />);++ await user.click(screen.getAllByLabelText('Select row')[0]);+ rerender(<SelectionTable hasRowHighlight={false} />);+ expect(readOverlay(screen.getAllByRole('row')[1])).toBe('');++ rerender(<SelectionTable hasRowHighlight />);+ expect(readOverlay(screen.getAllByRole('row')[1])).toBe(+ selectedBgColor,+ );+ });++ it('leaves unchecked rows without the variable', async () => {+ const user = userEvent.setup();+ render(<SelectionTable />);++ await user.click(screen.getAllByLabelText('Select row')[0]);++ expect(readOverlay(screen.getAllByRole('row')[2])).toBe('');+ });+ });});it('unsubscribes detached row refs instead of accumulating listeners', () => {diff --git a/packages/core/src/Table/plugins/selection/useTableSelection.tsx b/packages/core/src/Table/plugins/selection/useTableSelection.tsxindex 178b35403e..f628763e2c 100644--- a/packages/core/src/Table/plugins/selection/useTableSelection.tsx+++ b/packages/core/src/Table/plugins/selection/useTableSelection.tsx@@ -159,8 +159,24 @@ function applyRowSelectionStyle(}// Written on every pass, not just when painting: the flag can flip while a// row is already selected, and the wash has to come back off.- el.style.backgroundColor =- isSelected && hasRowHighlight ? selectedBgColor : '';+ const wash = isSelected && hasRowHighlight ? selectedBgColor : '';+ if (el.style.backgroundColor !== wash) {+ el.style.backgroundColor = wash;+ }+ // A pinned column paints its own opaque background over the row, so the+ // wash alone stops at the freeze line. Publishing it as the row overlay is+ // what lets useTableStickyColumns replay it on those cells — the same+ // contract TableRow honours for striping and hover.+ const currentOverlay = el.style.getPropertyValue(ROW_OVERLAY_VAR);+ if (wash === '') {+ if (currentOverlay !== '') {+ el.style.removeProperty(ROW_OVERLAY_VAR);+ }+ } else {+ if (currentOverlay !== wash) {+ el.style.setProperty(ROW_OVERLAY_VAR, wash);+ }+ }}// =============================================================================@@ -306,6 +322,13 @@ function SelectionCellContentInner<T extends Record<string, unknown>>({const selectedBgColor = colorVars['--color-accent-muted'];+/**+ * The row's current fill, republished for pinned cells to read. Declared as a+ * literal rather than imported because StyleX needs the same name as a static+ * key on the reading side, so there is no one constant both ends can share.+ */+const ROW_OVERLAY_VAR = '--table-row-overlay';+const selectionColumnStyles = stylex.create({center: {display: 'flex',diff --git a/packages/core/src/Table/useTableGroupedRows.doc.mjs b/packages/core/src/Table/useTableGroupedRows.doc.mjsindex df802e0716..353c9e39d4 100644--- a/packages/core/src/Table/useTableGroupedRows.doc.mjs+++ b/packages/core/src/Table/useTableGroupedRows.doc.mjs@@ -7,7 +7,7 @@ export const docs = {subComponentOf: 'Table',displayName: 'useTableGroupedRows',description:- "Hook that groups a flat data array into collapsible section rows. Each distinct groupBy value becomes a full-width section-header row with a chevron toggle, the group label, and a member count; collapsing hides that group's data rows while keeping the header visible. Mirrors useTableTreeState: the consumer owns the collapsedGroups set and the hook returns {data, plugin, idKey}: pass them to Table as data, plugins, and idKey respectively.",+ "Hook that groups a flat data array into collapsible section rows. Each distinct groupBy value becomes a full-width section-header row with a chevron toggle, the group label, and a member count; collapsing hides that group's data rows while keeping the header visible. Mirrors useTableTreeState: the consumer owns the collapsedGroups set and the hook returns {data, plugin, idKey}: pass them to Table as data, plugins, and idKey respectively. Grouping runs on the rows you hand it, so with pagination the order is filter, sort, slice, then group \u2014 sort by the group key first and the user's keys second, so a section's rows stay contiguous and each page appends to the bottom of the table instead of splicing rows in above the reader. A page that ends on a row count still cuts mid-section, and the heading then counts what has loaded rather than what exists \u2014 \"6\" quietly becoming \"10\". Where the full result set is in hand, carry the cut forward to the end of the section it lands in: every rendered section is then whole and its count is a total.",props: [{name: 'data',@@ -58,14 +58,14 @@ export const docs = {/** @type {import('@astryxdesign/cli/authoring').ComponentTranslationDoc} */export const docsDense = {description:- 'Groups a flat data array into collapsible section rows. Each groupBy value becomes a full-width header (chevron + label + count); collapsing hides its rows. Returns {data, plugin, idKey}: pass them to Table data / plugins / idKey. Consumer owns the collapsedGroups set.',+ 'Groups a flat data array into collapsible section rows. Each groupBy value becomes a full-width header (chevron + label + count); collapsing hides its rows. Returns {data, plugin, idKey}: pass them to Table data / plugins / idKey. Consumer owns the collapsedGroups set. Under pagination the order is filter, sort, slice, group \u2014 sort by the group key first so sections stay contiguous and pages append at the bottom. A row-count cut lands mid-section and the heading counts the page, not the section; where the whole result set is in hand, carry the cut to the end of the section it lands in so every rendered section is complete.',propDescriptions: {data: 'The flat data to group.',groupBy: "Derive a row's group key. Same key = same section.",collapsedGroups: 'Set of currently-collapsed group keys.',onToggleGroup: 'Called with the group key when a header is toggled.',renderGroupHeader:- "Custom header content (right of chevron). Default '<key> (<count>)'.",+ "Custom header content (right of chevron). Default '<key> (<count>)'. Args: (key, count, collapsed).",getRowKey: 'Stable key for a real row; positional fallback when omitted.',groupOrder: 'Pin these group keys first; others keep first-seen order.',},