An open source design system that's fully customizable and agent ready
TypeScript
fix(Table): keep the grouped-rows chevron pinned under a custom header (#6222)
Ernest183b7641f492
diff --git a/.changeset/grouped-rows-sticky-chevron.md b/.changeset/grouped-rows-sticky-chevron.mdnew file mode 100644index 0000000000..7cf7df462e--- /dev/null+++ b/.changeset/grouped-rows-sticky-chevron.md@@ -0,0 +1,6 @@+---+'@astryxdesign/core': patch+---++[fix] Keep grouped-row collapse chevrons pinned without shrinking custom headers, and increase them from 12px to 16px (#6222)+@ernesttdiff --git a/packages/core/src/Table/plugins/groupedRows/useTableGroupedRows.test.tsx b/packages/core/src/Table/plugins/groupedRows/useTableGroupedRows.test.tsxindex c98cb270d8..c122c7ab73 100644--- a/packages/core/src/Table/plugins/groupedRows/useTableGroupedRows.test.tsx+++ b/packages/core/src/Table/plugins/groupedRows/useTableGroupedRows.test.tsx@@ -1,5 +1,12 @@// Copyright (c) Meta Platforms, Inc. and affiliates.+/**+ * @file useTableGroupedRows.test.tsx+ * @input Table, grouped-row plugin, React testing utilities+ * @output Behavioral, accessibility, composition, and layout regression coverage+ * @position Focused tests for useTableGroupedRows+ */+import {describe, it, expect} from 'vitest';import {render, screen, fireEvent, within} from '@testing-library/react';import {useState, useCallback} from 'react';@@ -25,6 +32,41 @@ const columns: TableColumn<Person>[] = [{key: 'name', header: 'Name'}];const EMPTY = new Set<string>();+/** Read the StyleX declarations applied to an element under Vitest. */+function cssDeclarationsOf(element: Element): string[] {+ const classes = new Set(+ (element as HTMLElement).className.split(/\s+/).filter(Boolean),+ );+ const declarations: string[] = [];++ for (const sheet of Array.from(document.styleSheets)) {+ for (const rule of Array.from(sheet.cssRules)) {+ const text = rule.cssText;+ const brace = text.indexOf('{');+ if (brace === -1) {+ continue;+ }+ const selector = text.slice(0, brace).replaceAll(':not(#\\#)', '').trim();+ const match = /^\.([\w-]+)(.*)$/.exec(selector);+ if (!match || !classes.has(match[1])) {+ continue;+ }+ declarations.push(+ text+ .slice(brace + 1, text.lastIndexOf('}'))+ .trim()+ .replace(/;$/, ''),+ );+ }+ }++ return declarations;+}++function hasDeclaration(element: Element, declaration: string): boolean {+ return cssDeclarationsOf(element).some(value => value.includes(declaration));+}+function Harness({rows = people,initialCollapsed = EMPTY,@@ -167,6 +209,32 @@ describe('useTableGroupedRows', () => {expect(screen.getByText('Infra::1::open')).toBeInTheDocument();});+ it('keeps custom group headers full-width while pinning their chevron', () => {+ const builtIn = render(<Harness />);+ const builtInToggle = screen.getByRole('button', {+ name: 'Collapse group Core',+ });+ const builtInWrapper = builtInToggle.parentElement;+ expect(builtInWrapper).not.toBeNull();+ expect(hasDeclaration(builtInWrapper!, 'position: sticky')).toBe(true);+ expect(hasDeclaration(builtInWrapper!, 'width: fit-content')).toBe(true);+ builtIn.unmount();++ render(<Harness renderGroupHeader={key => <span>{key}</span>} />);+ const customToggle = screen.getByRole('button', {+ name: 'Collapse group Core',+ });+ const customWrapper = customToggle.parentElement;+ expect(customWrapper).not.toBeNull();++ // Preserve the custom renderer's full-row containing block. Only the+ // plugin-owned chevron is sticky, so it remains reachable on horizontal+ // scroll without constraining custom content to fit-content.+ expect(hasDeclaration(customWrapper!, 'position: sticky')).toBe(false);+ expect(hasDeclaration(customWrapper!, 'width: fit-content')).toBe(false);+ expect(hasDeclaration(customToggle, 'position: sticky')).toBe(true);+ });+it('renders nothing (no group headers) for empty data', () => {render(<Harness rows={[]} />);// Column header row still renders; no group header rows.diff --git a/packages/core/src/Table/plugins/groupedRows/useTableGroupedRows.tsx b/packages/core/src/Table/plugins/groupedRows/useTableGroupedRows.tsxindex 1fce3a2c5d..56a4fa9a07 100644--- a/packages/core/src/Table/plugins/groupedRows/useTableGroupedRows.tsx+++ b/packages/core/src/Table/plugins/groupedRows/useTableGroupedRows.tsx@@ -5,7 +5,7 @@/*** @file useTableGroupedRows.tsx* @input React, StyleX, Icon, Table types + the flat data array- * @output Exports useTableGroupedRows hook + config/result types+ * @output Exports useTableGroupedRows hook + config/result types with layout-safe group headers* @position Grouped-rows plugin; consumed by Table via plugins prop** SYNC: When modified, update these files to stay in sync:@@ -132,26 +132,29 @@ const styles = stylex.create({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.+ // Shared row layout. Custom renderers keep this full-width so their layout+ // continues to use the full spanning cell.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: {+ // The built-in heading moves with its chevron and can safely shrink-wrap.+ headerInnerPinned: {+ insetInlineStart: 0,+ position: 'sticky',width: 'fit-content',},+ // A custom header may rely on the full row width. Pin only the plugin-owned+ // control so custom content keeps its original containing block.+ customHeaderChevronPinned: {+ insetInlineStart: spacingVars['--spacing-1'],+ position: 'sticky',+ zIndex: 1,+ },// Standalone chevron button with no heavy chrome (transparent, borderless,// zero padding) so the icon sits flush with the start of the table// (Ernest review #1) while staying keyboard-operable.@@ -388,13 +391,16 @@ export function useTableGroupedRows<T extends Record<string, unknown>>(<span{...stylex.props(styles.headerInner,- !renderGroupHeader && styles.headerInnerFitContent,+ !renderGroupHeader && styles.headerInnerPinned,)}>{/* Standalone chevron button, flush with the table's startedge (no heavy button chrome) — the keyboard control. */}<buttontype="button"- {...stylex.props(styles.chevron)}+ {...stylex.props(+ styles.chevron,+ renderGroupHeader && styles.customHeaderChevronPinned,+ )}onClick={e => {e.stopPropagation();toggle();@@ -411,7 +417,12 @@ export function useTableGroupedRows<T extends Record<string, unknown>>(aria-expanded={!collapsed}><Iconicon="chevronRight"- size="xsm"+ // 16px, not the 12px this started at. The chevron is the+ // control for the whole section and sits beside a heading,+ // so at 12 it read as decoration on the label rather than+ // the thing you press, and it was the smallest hit target+ // in the table.+ size="sm"// The rotation rides on the glyph rather than a wrapper// span so the theme target below reaches both the mark and// its open/closed transform.