Repository navigation
Table: component-based styling + selection plugin - #123
Conversation
Review NotesOverallThe component-based styling refactor is the right move — styling co-located with components, plugins handle behavior + structure, Architecture: Header Cell Slot Model (forward-looking)Based on discussion about how the internal table system handles structured headers, we should plan for header cells to support a slot-based layout that plugins compose into: When sorting/filtering/resize plugins land, interface HeaderCellRenderProps {
htmlProps: HTMLAttributes<HTMLTableCellElement>;
styles: StyleXStyles[];
// Slot content — plugins compose into these
beforeCell?: ReactNode;
afterCell?: ReactNode;
beforeLabel?: ReactNode;
afterLabel?: ReactNode;
extraContent?: ReactNode;
label: ReactNode; // initialized from column.header
}Plugins transform by appending to their target slot:
Each plugin only touches its slot — they compose without knowing about each other. The header cell component stays simple, just rendering the layout. No changes needed in this PR — the current Smaller items
|
Replace plugin-based styling with component-based styling. XDSBaseTable
gains a `components` prop so XDSTable passes { Row, Cell, HeaderCell }
instead of a styling plugin. Components own their styles via
XDSTableContext, reading density/dividers/striped/hover from context.
Add XDSTableHeaderCell component for styled <th> elements with density,
header font, and divider styles. Add `extraStyles` prop to XDSTableRow,
XDSTableCell, and XDSTableHeaderCell for plugin-provided styles.
Add useXDSTableSelection hook — a table plugin providing row checkboxes,
select-all with indeterminate state, selected row highlighting, and
aria-selected attributes. Uses React Context for independent checkbox
re-rendering without triggering full row re-renders.
9d97871 to
6a057ae
Compare
PR Analysis Report📚 Storybook PreviewModified ComponentsCheckboxInput
Table
Bundle Size Summary
Accessibility AuditStatus: 3 accessibility violation(s) found. XDSCheckboxInput - 1 issue(s)
XDSTable - 1 issue(s)
Selection - 1 issue(s)
Component PreviewsIncludes interactive hover previews as animated GIFs. XDSCheckboxInputDefaultScreenshot: Interaction Preview: (view video) Run CheckedScreenshot: Interaction Preview: (view video) Run With DescriptionScreenshot: Interaction Preview: (view video) Run With Hidden LabelScreenshot: Interaction Preview: (view video) Run IndeterminateScreenshot: Interaction Preview: (view video) Run DisabledScreenshot: Interaction Preview: (view video) Run Disabled CheckedScreenshot: Interaction Preview: (view video) Run All VariationsScreenshot: Interaction Preview: (view video) Run Small SizeScreenshot: Interaction Preview: (view video) Run Size ComparisonScreenshot: Interaction Preview: (view video) Run With Start IconScreenshot: Interaction Preview: (view video) Run Start Icon VariationsScreenshot: Interaction Preview: (view video) Run With Error StatusScreenshot: Interaction Preview: (view video) Run With Warning StatusScreenshot: Interaction Preview: (view video) Run With Success StatusScreenshot: Interaction Preview: (view video) Run Status VariationsScreenshot: Interaction Preview: (view video) Run XDSTableDefaultScreenshot: Interaction Preview: (view video) Run CompactScreenshot: Interaction Preview: (view video) Run SpaciousScreenshot: Interaction Preview: (view video) Run Striped With HoverScreenshot: Interaction Preview: (view video) Run Grid DividersScreenshot: Interaction Preview: (view video) Run Column DividersScreenshot: Interaction Preview: (view video) Run No DividersScreenshot: Interaction Preview: (view video) Run Auto ColumnsScreenshot: Interaction Preview: (view video) Run Custom Cell RendererScreenshot: Interaction Preview: (view video) Run Children ModeScreenshot: Interaction Preview: (view video) Run All DensitiesScreenshot: Interaction Preview: (view video) Run Kitchen SinkScreenshot: Interaction Preview: (view video) Run SelectionDefaultScreenshot: Interaction Preview: (view video) Run With PreselectionScreenshot: Interaction Preview: (view video) Run Non Selectable RowsScreenshot: Interaction Preview: (view video) Run Disabled RowsScreenshot: Interaction Preview: (view video) Run CompactScreenshot: Interaction Preview: (view video) Run SpaciousScreenshot: Interaction Preview: (view video) Run With Striped RowsScreenshot: Interaction Preview: (view video) Run Generated by PR Enrichment workflow | Storybook | View full report |
Separate file (TableSelection.stories.tsx) nested under Core/XDSTable/Selection to avoid merge conflicts when parallelizing plugin development. Stories: Default, WithPreselection, NonSelectableRows, DisabledRows, Compact, Spacious, WithStripedRows
Aligns with XDS xstyle naming convention. 'additionalXStyles' signals these are extra StyleX styles layered on top of the component's own styles, distinct from consumer-facing 'xstyle' prop.
Verifies that selection changes don't cause unnecessary row re-renders:
- Single row selection: other rows stay at 1 render ✅
- Select-all: row content doesn't re-render ✅
- 3 sequential selections: unaffected rows stay at 1 render ✅
- Documents pitfall: inline plugins={{}} breaks memoization
Key finding: consumers must memoize the plugins record with useMemo()
for optimal performance. The plugin object itself is stable (useRef),
but the wrapping record must also be stable.
- Remove colgroup from XDSBaseTable — fixes plugin column injection
and prepares for future div-based grid layout
- Add useXDSBaseTablePlugins hook that converts named plugin records
to stable memoized arrays, comparing by plugin identity so inline
plugins={{}} does not break row memoization
- XDSTable now uses the hook instead of manual useMemo
- Selection plugin uses context-driven SelectionRowAttributes for
reactive aria-selected without depending on row re-renders
- Remove colgroup test, update selection tests for new memoization
The density padding (12px inline) was expanding the cell beyond the width constraint. Selection cell now uses tighter --spacing-2 padding and pins width with min/max/width all set to 40px.
| useEffect(() => { | ||
| const tr = ref.current?.parentElement; | ||
| if (!tr) return; | ||
| if (isSelected) { | ||
| tr.setAttribute('aria-selected', 'true'); | ||
| } else { | ||
| tr.removeAttribute('aria-selected'); | ||
| } | ||
| }, [isSelected]); |
There was a problem hiding this comment.
I'm worried about dropped renders potentially putting this into a bad state. We should rely on more straightforward props passing. It's find if the row element re-renders as long as we properly memoize the children cell from unnecessary updates.
| }, [isSelected]); | ||
|
|
||
| // Hidden <td> to get a DOM reference for finding the parent <tr> | ||
| return <td ref={ref} style={{display: 'none'}} aria-hidden="true" />; |
There was a problem hiding this comment.
Even with the ref update strategy this doesn't make sense. We can enable plugins to pass a ref to register with a row or cell.
| const configRef = useRef(config); | ||
| configRef.current = config; | ||
|
|
||
| // Return a stable plugin object via ref to avoid unnecessary re-renders |
There was a problem hiding this comment.
This works as long as the config is only callbacks but it's possible it could contain variants or visual updates. Ex. if htmlProps or styles update this plugin ref won't update and may not trigger the table to update. Those props may need to be memoized or shallow equal memoed.
Setting ref in render is generally considered a React antipattern so we should avoid it.
| /** Props for XDSTableCell — thin `<td>` wrapper */ | ||
| export interface XDSTableCellProps extends TdHTMLAttributes<HTMLTableCellElement> { | ||
| children?: ReactNode; | ||
| additionalXStyles?: StyleXStyles[]; |
There was a problem hiding this comment.
At this level, it can just be called xstyle. At the plugin level, the styles we apply for the plugin should be additive (ex. plugin A and B apply different styles that add together). Maybe we consolidate on just xstyle as the prop in all cases for consistency.
| <td | ||
| ref={ref} | ||
| {...props} | ||
| {...stylex.props(...(additionalXStyles ?? []))}> |
There was a problem hiding this comment.
We should avoid recomputing [] each time. I think it can just be...
{...stylex.props(additionalXStyles)}
| } | ||
|
|
||
| if (additionalXStyles) { | ||
| cellStyles.push(...additionalXStyles); |
There was a problem hiding this comment.
cellStyles.push(...xstyle);
| /** Props for XDSTableRow — thin `<tr>` wrapper */ | ||
| export interface XDSTableRowProps extends HTMLAttributes<HTMLTableRowElement> { | ||
| children: ReactNode; | ||
| additionalXStyles?: StyleXStyles[]; |
There was a problem hiding this comment.
Same, this can just be xstyle
|
Let's also organize the plugins into their own folders, like |
…gins 1. Rename additionalXStyles → xstyle across Row/Cell/HeaderCell/types 2. Fix empty array recomputation: use stylex.props(xstyle) directly 3. Remove SelectionRowAttributes (imperative DOM updates) — use straightforward props passing via transformBodyRow instead 4. Remove pluginRef antipattern — use useMemo([config]) instead of setting ref in render 5. Move selection plugin to Table/plugins/selection/ folder Row re-renders on selection change are now expected. The important optimization is that checkbox content re-renders independently via SelectionContext.
- Move selection functional tests to plugins/selection/useXDSTableSelection.test.tsx - Move selection perf tests to plugins/selection/useXDSTableSelection-perf.test.tsx - Remove selection tests from XDSTable.test.tsx (65 tests remain) - Fix lint: remove unused TableHeaderCellComponentProps import from XDSBaseTable
…ader underline - Use xstyle prop instead of spreading stylex.props on selection cells - Accept both StyleXStyles and StyleXStyles[] for xstyle on cell components - Add box-sizing: border-box to all cell density styles - Scope last-row border removal to tbody to preserve header underline - Remove gap on CheckboxInput when label is hidden - Adjust selection column width to 36px
* Table: component-based styling + selection plugin
Replace plugin-based styling with component-based styling. XDSBaseTable
gains a `components` prop so XDSTable passes { Row, Cell, HeaderCell }
instead of a styling plugin. Components own their styles via
XDSTableContext, reading density/dividers/striped/hover from context.
Add XDSTableHeaderCell component for styled <th> elements with density,
header font, and divider styles. Add `extraStyles` prop to XDSTableRow,
XDSTableCell, and XDSTableHeaderCell for plugin-provided styles.
Add useXDSTableSelection hook — a table plugin providing row checkboxes,
select-all with indeterminate state, selected row highlighting, and
aria-selected attributes. Uses React Context for independent checkbox
re-rendering without triggering full row re-renders.
* Add selection plugin storybook stories
Separate file (TableSelection.stories.tsx) nested under Core/XDSTable/Selection
to avoid merge conflicts when parallelizing plugin development.
Stories: Default, WithPreselection, NonSelectableRows, DisabledRows,
Compact, Spacious, WithStripedRows
* Rename extraStyles → additionalXStyles
Aligns with XDS xstyle naming convention. 'additionalXStyles' signals
these are extra StyleX styles layered on top of the component's own
styles, distinct from consumer-facing 'xstyle' prop.
* Add selection plugin performance tests
Verifies that selection changes don't cause unnecessary row re-renders:
- Single row selection: other rows stay at 1 render ✅
- Select-all: row content doesn't re-render ✅
- 3 sequential selections: unaffected rows stay at 1 render ✅
- Documents pitfall: inline plugins={{}} breaks memoization
Key finding: consumers must memoize the plugins record with useMemo()
for optimal performance. The plugin object itself is stable (useRef),
but the wrapping record must also be stable.
* Remove colgroup, add useXDSBaseTablePlugins hook
- Remove colgroup from XDSBaseTable — fixes plugin column injection
and prepares for future div-based grid layout
- Add useXDSBaseTablePlugins hook that converts named plugin records
to stable memoized arrays, comparing by plugin identity so inline
plugins={{}} does not break row memoization
- XDSTable now uses the hook instead of manual useMemo
- Selection plugin uses context-driven SelectionRowAttributes for
reactive aria-selected without depending on row re-renders
- Remove colgroup test, update selection tests for new memoization
* Fix selection column width: 36px fixed with maxWidth
* Fix selection column width: override padding, pin with min/max/width
The density padding (12px inline) was expanding the cell beyond the
width constraint. Selection cell now uses tighter --spacing-2 padding
and pins width with min/max/width all set to 40px.
* Address PR feedback: xstyle rename, remove antipatterns, organize plugins
1. Rename additionalXStyles → xstyle across Row/Cell/HeaderCell/types
2. Fix empty array recomputation: use stylex.props(xstyle) directly
3. Remove SelectionRowAttributes (imperative DOM updates) — use
straightforward props passing via transformBodyRow instead
4. Remove pluginRef antipattern — use useMemo([config]) instead of
setting ref in render
5. Move selection plugin to Table/plugins/selection/ folder
Row re-renders on selection change are now expected. The important
optimization is that checkbox content re-renders independently
via SelectionContext.
* Colocate selection tests, fix lint warning
- Move selection functional tests to plugins/selection/useXDSTableSelection.test.tsx
- Move selection perf tests to plugins/selection/useXDSTableSelection-perf.test.tsx
- Remove selection tests from XDSTable.test.tsx (65 tests remain)
- Fix lint: remove unused TableHeaderCellComponentProps import from XDSBaseTable
* Fix selection plugin styling: use xstyle prop, add box-sizing, fix header underline
- Use xstyle prop instead of spreading stylex.props on selection cells
- Accept both StyleXStyles and StyleXStyles[] for xstyle on cell components
- Add box-sizing: border-box to all cell density styles
- Scope last-row border removal to tbody to preserve header underline
- Remove gap on CheckboxInput when label is hidden
- Adjust selection column width to 36px
* Table: component-based styling + selection plugin
Replace plugin-based styling with component-based styling. XDSBaseTable
gains a `components` prop so XDSTable passes { Row, Cell, HeaderCell }
instead of a styling plugin. Components own their styles via
XDSTableContext, reading density/dividers/striped/hover from context.
Add XDSTableHeaderCell component for styled <th> elements with density,
header font, and divider styles. Add `extraStyles` prop to XDSTableRow,
XDSTableCell, and XDSTableHeaderCell for plugin-provided styles.
Add useXDSTableSelection hook — a table plugin providing row checkboxes,
select-all with indeterminate state, selected row highlighting, and
aria-selected attributes. Uses React Context for independent checkbox
re-rendering without triggering full row re-renders.
* Add selection plugin storybook stories
Separate file (TableSelection.stories.tsx) nested under Core/XDSTable/Selection
to avoid merge conflicts when parallelizing plugin development.
Stories: Default, WithPreselection, NonSelectableRows, DisabledRows,
Compact, Spacious, WithStripedRows
* Rename extraStyles → additionalXStyles
Aligns with XDS xstyle naming convention. 'additionalXStyles' signals
these are extra StyleX styles layered on top of the component's own
styles, distinct from consumer-facing 'xstyle' prop.
* Add selection plugin performance tests
Verifies that selection changes don't cause unnecessary row re-renders:
- Single row selection: other rows stay at 1 render ✅
- Select-all: row content doesn't re-render ✅
- 3 sequential selections: unaffected rows stay at 1 render ✅
- Documents pitfall: inline plugins={{}} breaks memoization
Key finding: consumers must memoize the plugins record with useMemo()
for optimal performance. The plugin object itself is stable (useRef),
but the wrapping record must also be stable.
* Remove colgroup, add useXDSBaseTablePlugins hook
- Remove colgroup from XDSBaseTable — fixes plugin column injection
and prepares for future div-based grid layout
- Add useXDSBaseTablePlugins hook that converts named plugin records
to stable memoized arrays, comparing by plugin identity so inline
plugins={{}} does not break row memoization
- XDSTable now uses the hook instead of manual useMemo
- Selection plugin uses context-driven SelectionRowAttributes for
reactive aria-selected without depending on row re-renders
- Remove colgroup test, update selection tests for new memoization
* Fix selection column width: 36px fixed with maxWidth
* Fix selection column width: override padding, pin with min/max/width
The density padding (12px inline) was expanding the cell beyond the
width constraint. Selection cell now uses tighter --spacing-2 padding
and pins width with min/max/width all set to 40px.
* Address PR feedback: xstyle rename, remove antipatterns, organize plugins
1. Rename additionalXStyles → xstyle across Row/Cell/HeaderCell/types
2. Fix empty array recomputation: use stylex.props(xstyle) directly
3. Remove SelectionRowAttributes (imperative DOM updates) — use
straightforward props passing via transformBodyRow instead
4. Remove pluginRef antipattern — use useMemo([config]) instead of
setting ref in render
5. Move selection plugin to Table/plugins/selection/ folder
Row re-renders on selection change are now expected. The important
optimization is that checkbox content re-renders independently
via SelectionContext.
* Colocate selection tests, fix lint warning
- Move selection functional tests to plugins/selection/useXDSTableSelection.test.tsx
- Move selection perf tests to plugins/selection/useXDSTableSelection-perf.test.tsx
- Remove selection tests from XDSTable.test.tsx (65 tests remain)
- Fix lint: remove unused TableHeaderCellComponentProps import from XDSBaseTable
* Fix selection plugin styling: use xstyle prop, add box-sizing, fix header underline
- Use xstyle prop instead of spreading stylex.props on selection cells
- Accept both StyleXStyles and StyleXStyles[] for xstyle on cell components
- Add box-sizing: border-box to all cell density styles
- Scope last-row border removal to tbody to preserve header underline
- Remove gap on CheckboxInput when label is hidden
- Adjust selection column width to 36px
…9969) * docs(useLinkify): add hook docs and a comment-thread example block A HookDoc next to the hook source (usage, text and options params covering patterns/hasBuiltins, the ReactNode[] return, best practices), so astryx hook useLinkify and astryx search return it, and a template block naming useLinkify in exampleFor: the issue's scenario, a short comment thread in plain text where the URL and the email address become Links and a custom issue-reference pattern turns #123/#456 into tracker links, while a comment without matches stays plain. Removing the hook call removes every link, per INV28. A jsdom test asserts the four hrefs (url, mailto, two issue links) and that the plain note renders no anchor. Closes #9560 * Merge remote-tracking branch 'origin/main' into l3-9969 * docs(useLinkify): register the routes, fix the changeset, correct the global-flag and overlap wording Adds the hook doc and example to the ShadCN route lock and the sandbox export routes, gives the changeset its frontmatter and contributor credit, says a non-global pattern never finishes rendering when the text matches, and says the earliest match wins with custom patterns winning only at the same start. Drops a test assertion that could never fail. * test(cli): useLinkify now opens its own hook doc The recorded resolution for useLinkify moves from Link.doc.mjs to the new useLinkify.doc.mjs, as other hook-doc additions have done. Co-authored-by: Cindy Zhang <[email protected]>
Replace plugin-based styling with component-based styling. XDSBaseTable gains a
componentsprop so XDSTable passes { Row, Cell, HeaderCell } instead of a styling plugin. Components own their styles via XDSTableContext, reading density/dividers/striped/hover from context.Add XDSTableHeaderCell component for styled elements with density, header font, and divider styles. Add
extraStylesprop to XDSTableRow, XDSTableCell, and XDSTableHeaderCell for plugin-provided styles.Add useXDSTableSelection hook — a table plugin providing row checkboxes, select-all with indeterminate state, selected row highlighting, and aria-selected attributes. Uses React Context for independent checkbox re-rendering without triggering full row re-renders.