Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

feat(Table): add row-specific expansion labels (#6776)

Humberto Virtudes31ab2c3ef197
diff --git a/.changeset/table-row-expansion-accessible-names.md b/.changeset/table-row-expansion-accessible-names.md
new file mode 100644
index 0000000000..f38fbf083f
--- /dev/null
+++ b/.changeset/table-row-expansion-accessible-names.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[feat] Table: let row-expansion and tree plugins include row identities in localized expand and collapse labels.
+
+@humbertovirtudes
diff --git a/apps/storybook/stories/TableRowExpansion.stories.tsx b/apps/storybook/stories/TableRowExpansion.stories.tsx
index d7bf28e644..c5472c9c08 100644
--- a/apps/storybook/stories/TableRowExpansion.stories.tsx
+++ b/apps/storybook/stories/TableRowExpansion.stories.tsx
@@ -109,8 +109,8 @@ type Story = StoryObj;
/**
* Each row expands a full-width detail panel below it, rendered by
* `renderExpanded(item)`. Click the chevron (or right-click, then
- * "Expand/Collapse row") to toggle the panel. The consumer owns the
- * `expandedKeys` set.
+ * "Expand/Collapse row") to toggle the panel. `getRowLabel` gives each control
+ * a row-specific accessible name. The consumer owns the `expandedKeys` set.
*
* For hierarchical data (child rows that reuse the parent columns), use
* `useTableTreeData` + `useTableTreeState` instead.
@@ -125,6 +125,7 @@ export const DetailPanel: Story = {
expandedKeys,
onToggle: key => setExpandedKeys(prev => toggleKey(prev, key)),
getRowKey: item => item.id,
+ getRowLabel: item => item.customer,
renderExpanded: item => <OrderItems order={item} />,
});
diff --git a/apps/storybook/stories/TableTree.stories.tsx b/apps/storybook/stories/TableTree.stories.tsx
index 9a023330c1..05ac816d22 100644
--- a/apps/storybook/stories/TableTree.stories.tsx
+++ b/apps/storybook/stories/TableTree.stories.tsx
@@ -161,6 +161,7 @@ type Story = StoryObj;
* Hierarchical records rendered as a table. `useTableTreeState` flattens the
* nested data into the visible rows and owns the expanded set;
* `useTableTreeData` draws the indent + expander in the first column.
+ * `getRowLabel` gives each expander a row-specific accessible name.
*
* Collapsed branches are unmounted, not hidden — the `<tbody>` holds exactly
* the visible rows.
@@ -172,7 +173,10 @@ export const Default: Story = {
idKey: 'id',
defaultExpandedIds: ['eng'],
});
- const tree = useTableTreeData(treeConfig);
+ const tree = useTableTreeData({
+ ...treeConfig,
+ getRowLabel: item => item.name,
+ });
return (
<Table
diff --git a/packages/core/api-report.md b/packages/core/api-report.md
index ac2d19dd74..69f2982394 100644
--- a/packages/core/api-report.md
+++ b/packages/core/api-report.md
@@ -570,6 +570,7 @@ component CheckboxList(props: CheckboxListProps)
prop hasDividers?: boolean = false
prop isDisabled?: boolean = false
prop isLabelHidden?: boolean = false
+ prop isOptional?: boolean = false
prop isReadOnly?: boolean = false
prop label: string
prop onChange?: (values: string[]) => void
@@ -640,6 +641,7 @@ component CodeBlock(props: CodeBlockProps)
prop onCopy?: () => void
prop ref?: React.Ref<HTMLPreElement>
prop size?: 'sm' | 'md'
+ prop startLineNumber?: number = 1
prop syntaxTheme?: SyntaxThemeDefinition
prop title?: string
prop tokenizer?: (code: string, language: string) => { type: string; start: number; end: number }[] @deprecated
@@ -3344,7 +3346,8 @@ const durationDefaults: object
--duration-slow-min: '730ms'
--duration-slow: '975ms'
--duration-slow-max: '1300ms'
-const durationVars: stylex.VarGroup<Readonly<{ readonly '--duration-fast-min': "130ms"; readonly '--duration-fast': "175ms"; readonly '--duration-fast-max': "230ms"; readonly '--du … #4dd3e52f
+ --duration-exit: 'var(--duration-fast)'
+const durationVars: stylex.VarGroup<Readonly<{ readonly '--duration-fast-min': "130ms"; readonly '--duration-fast': "175ms"; readonly '--duration-fast-max': "230ms"; readonly '--du … #f2df5593
const easeDefaults: object
--ease-standard: 'cubic-bezier(0.24, 1, 0.4, 1)'
--ease-entrance: 'cubic-bezier(0.24, 1, 0.4, 1)'
@@ -6163,6 +6166,7 @@ interface UseTableRowExpansionConfig<T extends Record<string, unknown>>
expandedKeys: Set<string>
getIsItemExpandable?: (item: T) => boolean = all rows expandable
getRowKey: (item: T) => string
+ getRowLabel?: (item: T) => string
hasRowClickExpansion?: boolean = false (only the chevron toggles expansion).
onToggle: (key: string) => void
panelVariant?: 'muted' | 'transparent' = 'transparent'
@@ -6216,6 +6220,7 @@ interface UseTableStickyColumnsConfig
endKeys?: string[]
startKeys?: string[]
interface UseTableTreeDataConfig<T extends Record<string, unknown>>
+ getRowLabel?: (item: T) => string
getRowMeta: (item: T) => TableTreeRowMeta | undefined
hasExpandAllControl?: boolean = false
hasExpandableRows: boolean
@@ -9902,6 +9907,7 @@ var --container-padding-block-end (./astryx.css)
var --container-padding-block-start (./astryx.css)
var --container-padding-inline-end (./astryx.css)
var --container-padding-inline-start (./astryx.css)
+var --duration-exit (./astryx.css)
var --duration-fast (./astryx.css)
var --duration-fast-max (./astryx.css)
var --duration-fast-min (./astryx.css)
diff --git a/packages/core/locales/en.json b/packages/core/locales/en.json
index 7cde835ef0..cea2e91f83 100644
--- a/packages/core/locales/en.json
+++ b/packages/core/locales/en.json
@@ -1631,10 +1631,18 @@
"defaultMessage": "Collapse row",
"description": "Screen-reader-only label on the row-expand chevron when the row is currently expanded. Part of the four-way expand/collapse set."
},
+ "@astryx.tableRowExpansion.collapseRowNamed": {
+ "defaultMessage": "Collapse {label}",
+ "description": "Aria label for an expanded row expansion control when a human-readable identity is available. `label` is the row identity from getRowLabel."
+ },
"@astryx.tableRowExpansion.expandRow": {
"defaultMessage": "Expand row",
"description": "Screen-reader-only label on the row-expand chevron when the row is currently collapsed. Part of a four-way set with `collapseRow`, `expandAllRows`, `collapseAllRows`."
},
+ "@astryx.tableRowExpansion.expandRowNamed": {
+ "defaultMessage": "Expand {label}",
+ "description": "Aria label for a collapsed row expansion control when a human-readable identity is available. `label` is the row identity from getRowLabel."
+ },
"@astryx.tableRowExpansion.columnHeader": {
"defaultMessage": "Row expansion",
"description": "Screen-reader-only header for the leading column that holds the per-row expand/collapse chevrons. The column shows no visible label."
@@ -1691,10 +1699,18 @@
"defaultMessage": "Collapse row",
"description": "Aria label for the Table tree-data expander chevron when the row is currently expanded."
},
+ "@astryx.tableTree.collapseRowNamed": {
+ "defaultMessage": "Collapse {label}",
+ "description": "Aria label for an expanded Table tree-data row when a human-readable identity is available. `label` is the row identity from getRowLabel."
+ },
"@astryx.tableTree.expandRow": {
"defaultMessage": "Expand row",
"description": "Aria label for the Table tree-data expander chevron when the row is currently collapsed."
},
+ "@astryx.tableTree.expandRowNamed": {
+ "defaultMessage": "Expand {label}",
+ "description": "Aria label for a collapsed Table tree-data row when a human-readable identity is available. `label` is the row identity from getRowLabel."
+ },
"@astryx.tableTree.collapseAllRows": {
"defaultMessage": "Collapse all rows",
"description": "Aria label for the Table tree-data header toggle when all rows are expanded and clicking it collapses them."
diff --git a/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.test.tsx b/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.test.tsx
index 7ed74d16ac..32ae66d319 100644
--- a/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.test.tsx
+++ b/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.test.tsx
@@ -64,6 +64,7 @@ function Harness({
panelVariant,
dividers,
isStriped,
+ getRowLabel,
}: {
initialExpanded?: Set<string>;
isItemExpandable?: (item: Row) => boolean;
@@ -74,6 +75,7 @@ function Harness({
panelVariant?: 'muted' | 'transparent';
dividers?: 'rows' | 'columns' | 'grid' | 'none';
isStriped?: boolean;
+ getRowLabel?: (item: Row) => string;
}) {
const [expandedKeys, setExpandedKeys] = useState(initialExpanded);
const expansion = useTableRowExpansion<Row>({
@@ -93,6 +95,7 @@ function Harness({
getIsItemExpandable: isItemExpandable,
hasRowClickExpansion,
panelVariant,
+ getRowLabel,
});
return (
<Table
@@ -108,6 +111,73 @@ function Harness({
}
describe('useTableRowExpansion (detail panel)', () => {
+ it.each(['omitted', 'blank', 'named'] as const)(
+ 'resolves %s labels inside the Table provider and follows locale changes',
+ mode => {
+ function LocalizedTable({locale}: {locale: 'fr' | 'de'}) {
+ const [expandedKeys, setExpandedKeys] = useState(EMPTY_KEYS);
+ const expansion = useTableRowExpansion<Row>({
+ expandedKeys,
+ onToggle: key =>
+ setExpandedKeys(prev =>
+ prev.has(key) ? EMPTY_KEYS : new Set([key]),
+ ),
+ getRowKey: item => item.id,
+ renderExpanded: defaultRenderExpanded,
+ getRowLabel:
+ mode === 'omitted'
+ ? undefined
+ : mode === 'blank'
+ ? () => ' '
+ : item => item.name,
+ });
+ return (
+ <InternationalizationProvider
+ locale={locale}
+ overrides={{
+ fr: {
+ '@astryx.tableRowExpansion.expandRow': 'Développer la ligne',
+ '@astryx.tableRowExpansion.collapseRow': 'Réduire la ligne',
+ '@astryx.tableRowExpansion.expandRowNamed':
+ 'Développer {label}',
+ '@astryx.tableRowExpansion.collapseRowNamed': 'Réduire {label}',
+ },
+ de: {
+ '@astryx.tableRowExpansion.expandRow': 'Zeile öffnen',
+ '@astryx.tableRowExpansion.collapseRow': 'Zeile schließen',
+ '@astryx.tableRowExpansion.expandRowNamed': '{label} öffnen',
+ '@astryx.tableRowExpansion.collapseRowNamed':
+ '{label} schließen',
+ },
+ }}>
+ <Table
+ data={rows}
+ columns={columns}
+ idKey="id"
+ plugins={{expansion}}
+ />
+ </InternationalizationProvider>
+ );
+ }
+ const named = mode === 'named';
+ const view = render(<LocalizedTable locale="fr" />);
+ const trigger = screen.getAllByRole('button', {
+ name: named ? 'Développer Ada' : 'Développer la ligne',
+ })[0];
+ fireEvent.click(trigger);
+ expect(
+ screen.getByRole('button', {
+ name: named ? 'Réduire Ada' : 'Réduire la ligne',
+ }),
+ ).toHaveAttribute('aria-expanded', 'true');
+ view.rerender(<LocalizedTable locale="de" />);
+ expect(
+ screen.getByRole('button', {
+ name: named ? 'Ada schließen' : 'Zeile schließen',
+ }),
+ ).toHaveAttribute('aria-expanded', 'true');
+ },
+ );
it('renders an "Expand row" chevron button for every expandable row', () => {
render(<Harness />);
expect(screen.getAllByRole('button', {name: /expand row/i})).toHaveLength(
@@ -115,6 +185,50 @@ describe('useTableRowExpansion (detail panel)', () => {
);
});
+ it('names each expansion control when getRowLabel is provided', () => {
+ render(<Harness getRowLabel={item => item.name} />);
+
+ expect(
+ screen.getByRole('button', {name: 'Expand Ada'}),
+ ).toBeInTheDocument();
+ expect(screen.getByRole('button', {name: 'Expand Bo'})).toBeInTheDocument();
+ expect(screen.getByRole('button', {name: 'Expand Cy'})).toBeInTheDocument();
+ });
+
+ it('keeps the row identity when the expansion state changes', () => {
+ render(
+ <Harness
+ initialExpanded={new Set(['a'])}
+ getRowLabel={item => item.name}
+ />,
+ );
+
+ expect(screen.getByRole('button', {name: 'Collapse Ada'})).toHaveAttribute(
+ 'aria-expanded',
+ 'true',
+ );
+ expect(screen.getByRole('button', {name: 'Expand Bo'})).toHaveAttribute(
+ 'aria-expanded',
+ 'false',
+ );
+ });
+
+ it('falls back to the generic label when getRowLabel returns blank text', () => {
+ render(<Harness getRowLabel={() => ' '} />);
+
+ expect(screen.getAllByRole('button', {name: 'Expand row'})).toHaveLength(3);
+ });
+
+ it('keeps the context-menu action generic when row-specific labels are enabled', () => {
+ render(<Harness getRowLabel={item => item.name} />);
+
+ fireEvent.contextMenu(screen.getByText('Ada'));
+ expect(
+ screen.getAllByRole('menuitem', {name: 'Expand row', hidden: true})
+ .length,
+ ).toBeGreaterThan(0);
+ });
+
it('does not render the detail panel while collapsed', () => {
render(<Harness />);
expect(screen.queryByTestId('panel')).not.toBeInTheDocument();
diff --git a/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx b/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx
index 06bccd8dd3..42e82bfddb 100644
--- a/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx
+++ b/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx
@@ -102,6 +102,17 @@ export interface UseTableRowExpansionConfig<T extends Record<string, unknown>> {
* it is expanded. Receives the row's item.
*/
renderExpanded: (item: T) => ReactNode;
+ /**
+ * Derive a human-readable row identity for the expansion control's accessible
+ * name. The plugin combines it with localized expand/collapse wording. Blank
+ * labels fall back to the generic row label.
+ *
+ * @example
+ * ```
+ * getRowLabel: item => item.name
+ * ```
+ */
+ getRowLabel?: (item: T) => string;
/**
* Control which rows are expandable. Non-expandable rows show no chevron, no
* context-menu action, and never render a panel. @default all rows expandable
@@ -345,13 +356,22 @@ const chevronOffsetStyles = stylex.create({
// =============================================================================
function ExpansionChevron({
+ rowLabel,
isExpanded,
onToggle,
}: {
+ rowLabel?: string;
isExpanded: boolean;
onToggle: () => void;
}) {
const t = useComponentTranslator();
+ const ariaLabel = rowLabel
+ ? isExpanded
+ ? t('@astryx.tableRowExpansion.collapseRowNamed', {label: rowLabel})
+ : t('@astryx.tableRowExpansion.expandRowNamed', {label: rowLabel})
+ : isExpanded
+ ? t('@astryx.tableRowExpansion.collapseRow')
+ : t('@astryx.tableRowExpansion.expandRow');
const ctx = useTableContext();
return (
<button
@@ -365,11 +385,7 @@ function ExpansionChevron({
e.stopPropagation();
onToggle();
}}
- aria-label={
- isExpanded
- ? t('@astryx.tableRowExpansion.collapseRow')
- : t('@astryx.tableRowExpansion.expandRow')
- }
+ aria-label={ariaLabel}
aria-expanded={isExpanded}>
<Icon
icon="chevronRight"
@@ -584,6 +600,7 @@ function ExpansionSnapshot({
* return next;
* }),
* getRowKey: item => item.id,
+ * getRowLabel: item => item.name,
* renderExpanded: item => <OrderDetails order={item} />,
* });
* <Table data={data} columns={columns} idKey="id" plugins={{expansion}} />;
@@ -597,6 +614,7 @@ export function useTableRowExpansion<T extends Record<string, unknown>>(
onToggle,
getRowKey,
renderExpanded,
+ getRowLabel,
getIsItemExpandable,
hasRowClickExpansion,
panelVariant = 'transparent',
@@ -841,15 +859,17 @@ export function useTableRowExpansion<T extends Record<string, unknown>>(
return null;
}
const key = getRowKey(item);
+ const isExpanded = expandedKeys.has(key);
return (
<ExpansionChevron
- isExpanded={expandedKeys.has(key)}
+ rowLabel={getRowLabel?.(item)?.trim() || undefined}
+ isExpanded={isExpanded}
onToggle={() => onToggle(key)}
/>
);
},
}),
- [expandedKeys, onToggle, getRowKey, getIsItemExpandable, t],
+ [expandedKeys, onToggle, getRowKey, getIsItemExpandable, getRowLabel, t],
);
return useMemo(
diff --git a/packages/core/src/Table/plugins/tree/useTableTreeData.test.tsx b/packages/core/src/Table/plugins/tree/useTableTreeData.test.tsx
index 7dc064d9c1..aa8f3bdc44 100644
--- a/packages/core/src/Table/plugins/tree/useTableTreeData.test.tsx
+++ b/packages/core/src/Table/plugins/tree/useTableTreeData.test.tsx
@@ -59,9 +59,15 @@ function TreeTable(
data?: FileRow[];
hasExpandAllControl?: boolean;
hasRowClickExpansion?: boolean;
+ getRowLabel?: (item: FileRow) => string;
},
) {
- const {hasExpandAllControl, hasRowClickExpansion, ...stateProps} = props;
+ const {
+ hasExpandAllControl,
+ hasRowClickExpansion,
+ getRowLabel,
+ ...stateProps
+ } = props;
const {visibleData, treeConfig} = useTableTreeState<FileRow>({
data: props.data ?? fileTree,
idKey: 'id',
@@ -71,6 +77,7 @@ function TreeTable(
...treeConfig,
hasExpandAllControl,
hasRowClickExpansion,
+ getRowLabel,
});
return (
@@ -108,6 +115,48 @@ describe('useTableTreeData — expander', () => {
expect(within(readmeRow).queryByRole('button')).toBeNull();
});
+ it('names top-level and nested expansion controls when getRowLabel is provided', () => {
+ render(
+ <TreeTable
+ defaultExpandedIds={['src']}
+ getRowLabel={item => item.name}
+ />,
+ );
+
+ expect(
+ within(getRowByText('src')).getByRole('button', {name: 'Collapse src'}),
+ ).toBeInTheDocument();
+ expect(
+ within(getRowByText('components')).getByRole('button', {
+ name: 'Expand components',
+ }),
+ ).toBeInTheDocument();
+ });
+
+ it('falls back to the generic label when getRowLabel returns blank text', () => {
+ render(<TreeTable getRowLabel={() => ' '} />);
+
+ expect(
+ within(getRowByText('src')).getByRole('button', {name: 'Expand row'}),
+ ).toBeInTheDocument();
+ });
+
+ it('updates expansion control names when getRowLabel changes', () => {
+ const {rerender} = render(<TreeTable getRowLabel={item => item.name} />);
+
+ expect(
+ within(getRowByText('src')).getByRole('button', {name: 'Expand src'}),
+ ).toBeInTheDocument();
+
+ rerender(<TreeTable getRowLabel={item => `Folder ${item.name}`} />);
+
+ expect(
+ within(getRowByText('src')).getByRole('button', {
+ name: 'Expand Folder src',
+ }),
+ ).toBeInTheDocument();
+ });
+
it('expands children on click and relabels the button "Collapse row"', async () => {
const user = userEvent.setup();
render(<TreeTable />);
diff --git a/packages/core/src/Table/plugins/tree/useTableTreeData.tsx b/packages/core/src/Table/plugins/tree/useTableTreeData.tsx
index 21b67b100b..1e69402ffd 100644
--- a/packages/core/src/Table/plugins/tree/useTableTreeData.tsx
+++ b/packages/core/src/Table/plugins/tree/useTableTreeData.tsx
@@ -87,6 +87,17 @@ export interface UseTableTreeDataConfig<T extends Record<string, unknown>> {
getRowMeta: (item: T) => TableTreeRowMeta | undefined;
/** Toggle a row's expansion. */
onToggleItem: (item: T) => void;
+ /**
+ * Derive a human-readable row identity for the expander's accessible name.
+ * The plugin combines it with localized expand/collapse wording. Blank labels
+ * fall back to the generic row label.
+ *
+ * @example
+ * ```
+ * getRowLabel: item => item.name
+ * ```
+ */
+ getRowLabel?: (item: T) => string;
/**
* Whether any row in the dataset is expandable. When false the plugin is
* a no-op: no expanders, no indent, no tree ARIA — flat data renders
@@ -164,38 +175,42 @@ function createTreeStore<T extends Record<string, unknown>>(
const TreeStoreContext = createContext<TreeStore<any> | null>(null);
TreeStoreContext.displayName = 'TreeStoreContext';
-/** Indent token -> index, for the numeric row snapshot. */
+/** Indent token -> index, for the primitive row snapshot. */
const INDENT_INDEX = {sm: 0, md: 1, lg: 2} as const;
/**
- * Encode a row's tree meta as a primitive for useSyncExternalStore —
- * object snapshots would tear. The indent token participates so a
- * runtime `indent` change re-renders the affected cells.
+ * Encode a row's tree meta and optional accessible label as a primitive for
+ * useSyncExternalStore — object snapshots would tear. The numeric fast path is
+ * retained when getRowLabel is absent. When it is present, the derived label
+ * participates so config-only label changes re-render the affected cells.
* Encoding: level * 16 + indentIndex * 4 + hasChildren * 2 + isExpanded;
* -1 = no meta.
*/
-function encodeRowMeta<T extends Record<string, unknown>>(
+function getRowSnapshot<T extends Record<string, unknown>>(
config: UseTableTreeDataConfig<T>,
item: T,
-): number {
+): number | string {
const meta = config.getRowMeta(item);
if (!meta) {
return -1;
}
- return (
+ const metaSnapshot =
meta.level * 16 +
INDENT_INDEX[config.indent ?? 'md'] * 4 +
(meta.hasChildren ? 2 : 0) +
- (meta.isExpanded ? 1 : 0)
- );
+ (meta.isExpanded ? 1 : 0);
+ if (!config.getRowLabel) {
+ return metaSnapshot;
+ }
+ return `${metaSnapshot}\u0000${config.getRowLabel(item)?.trim() ?? ''}`;
}
-function useRowMetaSnapshot<T extends Record<string, unknown>>(
+function useRowSnapshot<T extends Record<string, unknown>>(
store: TreeStore<T>,
item: T,
-): number {
+): number | string {
const getSnapshot = useCallback(
- () => encodeRowMeta(store.getConfig(), item),
+ () => getRowSnapshot(store.getConfig(), item),
[store, item],
);
@@ -324,11 +339,22 @@ const treeStyles = stylex.create({
function TreeExpander({
isExpanded,
onToggle,
+ rowLabel,
}: {
isExpanded: boolean;
onToggle: () => void;
+ rowLabel?: string;
}) {
const t = useComponentTranslator();
+ const normalizedRowLabel = rowLabel?.trim();
+ const ariaLabel = normalizedRowLabel
+ ? isExpanded
+ ? t('@astryx.tableTree.collapseRowNamed', {label: normalizedRowLabel})
+ : t('@astryx.tableTree.expandRowNamed', {label: normalizedRowLabel})
+ : isExpanded
+ ? t('@astryx.tableTree.collapseRow')
+ : t('@astryx.tableTree.expandRow');
+
return (
<button
type="button"
@@ -337,11 +363,7 @@ function TreeExpander({
e.stopPropagation();
onToggle();
}}
- aria-label={
- isExpanded
- ? t('@astryx.tableTree.collapseRow')
- : t('@astryx.tableTree.expandRow')
- }
+ aria-label={ariaLabel}
aria-expanded={isExpanded}>
<Icon
icon="chevronRight"
@@ -440,9 +462,9 @@ function TreeCellContentInner<T extends Record<string, unknown>>({
item: T;
children: ReactNode;
}) {
- // Subscribe to this row's structural meta so a toggle re-renders only
- // the affected cells.
- useRowMetaSnapshot(store, item);
+ // Subscribe to this row's structural meta and derived label so only affected
+ // cells re-render when either changes.
+ useRowSnapshot(store, item);
const config = store.getConfig();
const meta = config.getRowMeta(item);
@@ -463,6 +485,7 @@ function TreeCellContentInner<T extends Record<string, unknown>>({
<TreeExpander
isExpanded={meta.isExpanded}
onToggle={() => store.getConfig().onToggleItem(item)}
+ rowLabel={config.getRowLabel?.(item)}
/>
) : (
<span {...stylex.props(treeStyles.leafSpacer)} />
diff --git a/packages/core/src/Table/useTableRowExpansion.doc.mjs b/packages/core/src/Table/useTableRowExpansion.doc.mjs
index 1c2d753dbe..84b9a32284 100644
--- a/packages/core/src/Table/useTableRowExpansion.doc.mjs
+++ b/packages/core/src/Table/useTableRowExpansion.doc.mjs
@@ -28,6 +28,12 @@ export const docs = {
description: 'Derive a stable unique key from a row item.',
required: true,
},
+ {
+ name: 'getRowLabel',
+ type: '(item: T) => string',
+ description:
+ 'Derive a human-readable row identity for the chevron accessible name. Astryx combines it with localized expand/collapse wording. Omit it, or return blank text, to keep the generic "Expand row" and "Collapse row" labels.',
+ },
{
name: 'renderExpanded',
type: '(item: T) => ReactNode',
@@ -75,6 +81,7 @@ const expansion = useTableRowExpansion({
return next;
}),
getRowKey: item => item.id,
+ getRowLabel: item => item.name,
renderExpanded: item => <OrderDetails order={item} />,
});
@@ -122,6 +129,8 @@ export const docsDense = {
expandedKeys: 'Set of currently-expanded row keys. Consumer-owned.',
onToggle: 'Called with a row key when its expansion is toggled.',
getRowKey: 'Derive a stable unique key from a row item.',
+ getRowLabel:
+ 'Derive a row identity for the localized expand/collapse control label. Blank or omitted values keep the generic row label.',
renderExpanded:
'Render the full-width detail panel below an expanded row. Receives the row item.',
getIsItemExpandable:
diff --git a/packages/core/src/Table/useTableTreeData.doc.mjs b/packages/core/src/Table/useTableTreeData.doc.mjs
index 7d45769950..98493f2f19 100644
--- a/packages/core/src/Table/useTableTreeData.doc.mjs
+++ b/packages/core/src/Table/useTableTreeData.doc.mjs
@@ -19,9 +19,15 @@ export const docs = {
{
name: 'onToggleItem',
type: '(item: T) => void',
- description: 'Toggle a row\'s expansion.',
+ description: "Toggle a row's expansion.",
required: true,
},
+ {
+ name: 'getRowLabel',
+ type: '(item: T) => string',
+ description:
+ 'Derive a human-readable row identity for the expander. Astryx combines it with localized expand/collapse wording. Omit it, or return blank text, to keep the generic "Expand row" and "Collapse row" labels.',
+ },
{
name: 'hasExpandableRows',
type: 'boolean',
@@ -81,7 +87,10 @@ export const docs = {
idKey: 'id',
defaultExpandedIds: ['src'],
});
-const tree = useTableTreeData(treeConfig);
+const tree = useTableTreeData({
+ ...treeConfig,
+ getRowLabel: item => item.name,
+});
<Table data={visibleData} columns={columns} idKey="id" plugins={{tree}} />;`,
},
@@ -97,10 +106,13 @@ export const docsDense = {
getRowMeta:
'structural meta per visible row: {id, level (0-based), hasChildren, isExpanded}',
onToggleItem: 'toggle row expansion',
+ getRowLabel:
+ 'derive a row identity for the localized expand/collapse accessible name. Blank or omitted values keep the generic row label.',
hasExpandableRows: 'false => plugin is a no-op (no expanders/indent/ARIA)',
indent:
"indent step per level: 'sm' | 'md' | 'lg' (spacing-3/4/6). Defaults to 'md'.",
- treeColumnKey: 'column carrying indent + expander. Defaults to first column.',
+ treeColumnKey:
+ 'column carrying indent + expander. Defaults to first column.',
hasExpandAllControl:
'show expand-all/collapse-all toggle in tree column header. Needs isAllExpanded + onExpandAll/onCollapseAll (from useTableTreeState). Defaults to false.',
isAllExpanded: