Repository navigation
feat(core): add useTableRowExpansion plugin - #3441
Conversation
|
@humbertovirtudes is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
b464faf to
f1cb0cf
Compare
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Nice! I'm excited to get this feature in OSS! Small bug: the context menu seems to be broken when expand on row click is enabled. The context menu works in the other examples though so likely an issue with how we're resolving the combination of these features. Screen.Recording.2026-07-03.at.6.33.45.PM.movObserving the code written in storybook, there's quite a lot of extra code for managing the "allExpanded" behavior. IIRC we have some utilities for this internally so I wonder if we can make that better here too. For example, these lines are repeated: For the expansion state plugin if we can match similar API footprint as |
Expand/collapse tree rows inline using the inherited-columns pattern — child rows use the same columns as their parents, indented by depth. - Headless: consumer owns expandedKeys state; plugin provides the UI (chevron column, indentation, inline chevrons for nested rows). - useTableRowExpansionState helper flattens a tree into the visible rows. - Optional expand-all header toggle (isAllExpanded + onToggleExpandAll). - Optional expandOnRowClick to toggle by clicking anywhere in a row. - Contributes an Expand/Collapse context-menu action on every cell. - Storybook stories, docsite example block + doc, and unit tests.
…ext menu
Addresses review feedback on useTableRowExpansion:
- useTableRowExpansionState now mirrors useTableSelectionState: it takes
expandedKeys + setExpandedKeys and returns {data, expansionConfig}, deriving
the expand/collapse handlers and expand-all state internally. Consumers no
longer hand-roll allExpandableKeys / isAllExpanded / onToggleExpandAll.
- Renamed expandOnRowClick -> hasRowClickExpansion (has-prefix per the API
conventions for feature toggles).
- Fix: right-click context menu now opens across the entire cell. The trigger
wrapper fills the cell and carries the density padding (relocated off the
<td>), so right-clicking near a cell/row edge no longer falls through to the
browser's native menu. Added a triggerXstyle prop to ContextMenu.
- Simplified all stories, the docsite block, and tests to the new state API;
added expand-all / collapse-all and full-cell trigger regression tests.
8dc68f1 to
65b2e93
Compare
|
Thanks for the review! Both addressed in the latest push: Context menu bug — the trigger only wrapped the cell content, so right-clicking a cell's padding (or a narrow cell) fell through to the browser's native menu. Fixed by making the trigger fill the whole cell (density padding relocated onto the trigger, Expand-all boilerplate — moved into const {data, expansionConfig} = useTableRowExpansionState({
baseData: tree, getChildren, getRowKey, expandedKeys, setExpandedKeys,
});
const expansion = useTableRowExpansion(expansionConfig);Also ran the API through the conventions page and renamed |
cixzhang
left a comment
There was a problem hiding this comment.
This is a great turnaround — thank you Humberto. The useTableRowExpansionState hook mirrors useTableSelectionState nicely and takes all that expand-all/tree-walking boilerplate out of the consumer, and the full-cell right-click fix is clean. Excited to get this in.
One note, not blocking: triggerXstyle on ContextMenu is a new public escape hatch, and it's a little at odds with the rest of the Layer family — HoverCard and Tooltip intentionally use a display: contents trigger wrapper and don't expose trigger styling (the trigger is meant to be the child). Since the only consumer here is TableCell, I'd rather not grow ContextMenu's public API for it long-term. Let's land this as-is so the fix ships, and I'll file a follow-up to migrate ContextMenu's trigger to display: contents like Tooltip/HoverCard — best done alongside the positioning rework in #3465, since both touch how the trigger/menu anchor. Happy to pair on that.
What
Adds
useTableRowExpansion— expand/collapse tree rows inline. Uses the inherited-columns pattern: child rows use the same columns as their parents, indented by depth (like a file tree). Clicking the chevron, the header expand-all toggle, or right-clicking → "Expand/Collapse row" toggles a row's children.Design
expandedKeysstate.useTableRowExpansionStatemirrorsuseTableSelectionState's footprint — it takesexpandedKeys+setExpandedKeysand returns{data, expansionConfig}, deriving the flattened rows, per-row depth, expand/collapse handlers, and the expand-all state. Consumers no longer hand-roll theallExpandableKeys/isAllExpanded/onToggleExpandAllboilerplate.__expansionchevron column;transformColumnswraps the first user column'srenderCellto indent nested rows and render their inline chevron.isAllExpanded+onToggleExpandAll, both derived by the state hook).hasRowClickExpansionto toggle by clicking anywhere in the row.getIsItemExpandableto gate which rows are expandable (e.g. folders only) — also scopes expand-all.Full-cell context menu fix
While wiring the context-menu action, right-click only opened near a cell's content — right-clicking a cell's padding (or a narrow cell) fell through to the browser's native menu. Fixed by making the context-menu trigger fill the entire cell:
triggerXstyleprop toContextMenu(styles the right-click target wrapper).TableCellrelocates its density padding onto the trigger and stretches it to fill the cell (inline-size/block-size: 100%, withblock-size: 100%on the<td>), so a right-click anywhere in the cell — content and padding, edge to edge — opens the menu.Validation
pnpm -F @astryxdesign/core build✅, lint ✅ (0 errors)InheritedColumns,LeafNodesNotExpandable,ExpandOnRowClick(all now use the simplified state API).useTableRowExpansionhook page + example block + doc.Notes
is*state,has*toggle,on*handlers).expandOnRowClickwas renamed tohasRowClickExpansionper the boolean-naming guidance.