Skip to content

feat(core): opt-in bulk-actions toolbar for useTableSelection (#5486) - #5489

Merged
humbertovirtudes merged 1 commit into
meta:mainfrom
humbertovirtudes:feat/table-selection-bulk-actions
Sep 30, 2026
Merged

humbertovirtudes merged 1 commit into
meta:mainfrom
humbertovirtudes:feat/table-selection-bulk-actions

Conversation

@humbertovirtudes

@humbertovirtudes humbertovirtudes commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR This PR adds a reusable TableSelectionToolbar that consumes shared selectionState from useTableSelectionState. useTableSelection remains behavior-only, while product callsites own actions and fixed or floating placement.

Closes #5486.
Follows up in #6474.

Problem

Row selection is common Table behavior, but bulk-action UI is product chrome. Putting action labels, handlers, copy, or layout inside useTableSelection would couple a behavioral plugin to one visual pattern.

The selection plugin should remain reusable without rendering React chrome. A separate component can consume the same controlled selection source so behavior and presentation remain synchronized.

What changed

  • Added public selectionState output to useTableSelectionState with selectedKeys, selectedCount, hasSelection, and complete clearSelection.
  • Added public TableSelectionToolbar, built on Astryx Toolbar.
  • Kept useTableSelection behavior-only. It still owns row controls, select-all behavior, callbacks, and selected-row semantics.
  • Kept product actions as React slot content rather than action configuration.
  • Added localized default labels for the toolbar, selected count, and complete clear action.
  • Migrated the fixed and floating Storybook examples to the wrapper.
  • Migrated the fixed and floating website examples to the wrapper.
  • Made the floating example a capped 640px ScrollableArea with logical block scrolling, conditional containment and focusability, and stable scrollbar geometry.
  • Added public docs, exports, a patch changeset, the generated ShadCN route-lock entry, and the reviewed documentation and sandbox route inventories.
  • Kept the hidden production ShadCN registry compatible with the stable package by requiring both a published import subpath and published component metadata before emitting a block.

Usage

const {selectionConfig, selectionState} = useTableSelectionState({
  data,
  idKey: 'id',
  selectedKeys,
  setSelectedKeys,
});
const selectionPlugin = useTableSelection(selectionConfig);

<TableSelectionToolbar
  selection={selectionState}
  startContent={productActions}
/>

<Table plugins={{selection: selectionPlugin}} />

selectionState.clearSelection() clears the complete controlled selection, including keys retained outside the current filtered or paginated view. The header checkbox keeps its existing view-scoped deselection behavior and preserves frozen keys.

Ownership boundary

useTableSelection owns:

  • row and select-all controls
  • controlled selection callbacks
  • selected-row semantics

TableSelectionToolbar owns:

  • Astryx Toolbar delegation
  • default sm size and muted variant
  • visibility while selection exists
  • synchronized selected count
  • complete clear action

The product callsite owns:

  • action content and handlers
  • copy overrides
  • fixed versus floating placement
  • surrounding scroll-container geometry

Layout variants

Variant Layout Intended use
Fixed In flow above the table Standard tables where the page may reflow when selection appears
Floating Sticky inside a capped example scrollport Long tables where actions remain available while rows scroll

The floating recipe keeps the toolbar outside Table's horizontal overflow wrapper, reserves its layout space so selection causes zero table movement, and pins the rendered surface 16px from the example scrollport.

Test plan

  • 75 focused Table selection, toolbar, scrolling, and registry compatibility tests passed.
  • Storybook build/typecheck and targeted lint passed in CI.
  • Targeted CLI template tests passed: 5 tests.
  • Documentation and sandbox route-inventory regressions passed: 9 tests.
  • ShadCN source-import and published-component compatibility regressions passed; canary generation kept both examples while the published-package snapshot correctly omitted them.
  • All 13 network-free repository sync, knowledge, changeset, use-client, i18n, package-boundary, fixture, and setup checks passed.
  • Real-browser fixed verification passed: real Astryx Toolbar, sm, muted, synchronized count, complete clear, and outside Table's horizontal scroller.
  • Real-browser floating verification passed: at an 888px viewport the email column rendered at 160px, the table minimum width dropped from 516px to 396px, and the Table scroll wrapper had no horizontal overflow. Browser Bridge confirmed the 640px ScrollableArea had 1725px of scroll content, used a named default group with a tab stop while block overflow was active, contained overscroll only on the overflowing block axis, caused zero table movement, used local z-index: 1, and kept the toolbar 16px from the scrollport at scrollTop=300.

Review links

Self-review

The post-publish review found and fixed one callback edge case: renderSelectionLabel={() => null} now intentionally renders no count instead of falling back to the default count. The final review follow-up replaced the hand-rolled floating scrollport with ScrollableArea, removed the nested Metrics region, scoped sticky stacking locally, and consolidated its placement geometry. The rebase retained main's source-import registry compatibility check; the CI follow-up added the complementary published-component guard needed when a new named export uses an existing package subpath. The adversarial follow-up found no blocker. Residual risk: named-export gating relies on accurate block componentsUsed metadata, with the published-package compile remaining the final backstop. Preview links depend on the PR deployment finishing for commit ab4737a1e3420bc510083c6ffedc91bf6c40dfae.

This PR was generated with AI assistance. The human author reviewed and approved the changes.

@vercel

vercel Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Sep 28, 2026 6:58pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 25, 2026
@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Aug 25, 2026
@github-actions

github-actions Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.9KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

1 of 420 shot(s) changed. View the report

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
SideNav Resizable in AppShell probe dark 3,208
SideNav — Resizable in AppShell — probe dark
BeforeAfterDiff
Before visual regression frame After visual regression frame Pixel difference frame

Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

github-actions Bot added a commit that referenced this pull request Aug 25, 2026
@humbertovirtudes
humbertovirtudes force-pushed the feat/table-selection-bulk-actions branch from 3305d1c to 759661f Compare August 28, 2026 14:43
github-actions Bot added a commit that referenced this pull request Aug 28, 2026
@humbertovirtudes
humbertovirtudes marked this pull request as ready for review August 28, 2026 15:13
@rubyycheung

Copy link
Copy Markdown
Contributor

The bulk-actions behavior looks good. I have one visual spacing suggestion after testing it inside a padded Card: the outlined toolbar currently reads as another full-width container and feels cramped against the surrounding layout.

Could we remove the toolbar border and inset the tinted surface by 8px on each logical inline side? That offset comes from the actual selection geometry: a 20px small checkbox centered in the 36px selection column. It aligns the toolbar surface with the outer edge of the checkboxes while allowing the table rows to remain full bleed.

@ernestt

ernestt commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Current:
CleanShot 2026-08-31 at 14 38 52

Ideal:
CleanShot 2026-08-31 at 14 39 29

I recreated a table template trying to replicate what we had in www. The bulk actions bar here is a full bleed section. With actions on the left side, and unselection and total selected count on the right. Mainly because the column heading also has a bulk checkbox already anyways so colocating the actions to be close by seems to make more sense.

@ernestt ernestt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bulk action bar visuals commented above

@humbertovirtudes

Copy link
Copy Markdown
Contributor Author

@ernestt Im thinking we can have 2 variants for bulk action bars - one that remains at the top of the table, full bleed and static as you suggested, and another that is floating - and remains visible even when the user scrolled way past the header - to avoid having to scroll back to the top in order to trigger any bulk actions.

Thoughts?

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval is waiting on a maintainer to provide or identify the current governing specs for the new public TableSelectionToolbar / selectionState contract, including complete-clear behavior and the fixed/floating placement recipes, and for production registry omission of blocks that depend on unreleased components.

One implementation issue remains independently actionable: the floating story and copyable template pair vertical scrolling with overscrollBehavior: 'contain', which contains both axes. The current scrolling contract requires containment only on axes that actually overflow, so please scope this to the block axis or use the shared effective-scroll behavior.

Browser behavior was not independently rerun in this review.

[Automated review]

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval is waiting on a maintainer to provide or identify the current governing specs for the new public TableSelectionToolbar / selectionState contract, including complete-clear behavior and the fixed/floating placement recipes, and for omitting blocks that depend on unreleased components from the latest registry.

One implementation issue remains independently actionable: the floating story and copyable template pair block scrolling with overscrollBehavior: 'contain', which contains both axes. The current scrolling contract requires containment only on axes that actually overflow, so please scope this to the block axis or use the shared effective-scroll behavior.

Browser behavior was not independently rerun in this review.

[Automated review]

github-actions Bot added a commit that referenced this pull request Sep 23, 2026
@ernestt

ernestt commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

The behavior here is good — I'm happy with how the floating toolbar reads and with the ownership split between the plugin, the wrapper, and the callsite. In particular, keeping the toolbar outside Table's inline-axis scroll wrapper is the right call and is exactly what spec:AST-025 FR10/FR18 ask for: the block-axis sticky resolves to the outer block owner instead of being trapped by the table's own scroller. Not a blocker for the behavior.

What I'd like you to look at before this lands is whether the example scrollport can conform to the sticky/scrollable-area specs, since this is a CLI template and a Storybook story — whatever it does gets copied into consumer apps. spec:AST-025 is authority: current now and useScrollableArea / ScrollableArea are landed in packages/core, so the hand-rolled scrollport is no longer the house pattern.

Concretely, in styles.page on both the template block and the story:

  1. overscrollBehavior: 'contain' is unconditional. FR14 requires containment to be active only on axes that currently overflow — on the non-overflowing inline axis this is the dead scroll zone the requirement exists to prevent, and Chrome 144 changed behavior here (the spec calls that out as regression-sensitive).

  2. tabIndex={0} + role="region" are unconditional. FR12/AR1: a viewport enters the tab order only while an axis is effective. AST-025's current-state section names example scroll wrappers that are focusable by default as something adoption has to fix. The nested role="region" aria-label="Metrics" also adds a landmark that isn't a scroll target.

  3. overflowY: 'auto' is physical and hand-declared. FR1/FR17 want logical scroll intent, and the closed axis vocabulary rather than a raw CSS pair.

All three fall out for free if the example wraps the region in ScrollableArea (axis="block", overscroll="contain", a label) instead of styling a div. That's the reference composition per DEC-1, and it'd make the template teach the current pattern.

Two smaller things while you're in there:

  1. zIndex: 20 with no isolation owner. spec:AST-027 FR4/FR5 — no isolation: isolate on styles.page or styles.tableRegion, and that spec explicitly flags CLI-emitted templates as generated leaks needing explicit surface isolation. 20 also reads as a band rather than a local rank; 1 on an isolated surface does the same job.

  2. The placement math is fragile. paddingBlockStart + translateY + a negative marginBlockEnd, each repeating the same four-token calc() chain, to land the toolbar 16px from the scrollport. Any change to --size-element-sm or those spacing steps breaks it in three places at once. Worth a single custom property the three declarations read.

None of this changes what the toolbar does — it's all the container around it. Happy to pair on the ScrollableArea swap if it turns out to fight the Table wrapper.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval is waiting on a maintainer to provide or identify the governing spec for the new public TableSelectionToolbar / selectionState contract — including complete-clear behavior, the sm/muted and localized-label defaults, and the fixed and floating placement recipes — and for omitting blocks that depend on unreleased components from the latest registry. The current Table, Toolbar, and scrolling specs cover the adjacent mechanics, but they do not settle this new public addition, and the registry compatibility record is still draft.

The implementation issues raised in earlier revisions are resolved in this revision: the floating examples now use ScrollableArea with containment only on the overflowing block axis, real Toolbar delegation, and local stacking inside an isolated surface.

Browser behavior was not independently rerun in this review.

[Automated review]

humbertovirtudes

This comment was marked as outdated.

Add TableSelectionToolbar as a reusable selection-aware wrapper built on
Toolbar. Extend useTableSelectionState with selectionState for synchronized
selected keys, count, visibility, and complete clearing while keeping
useTableSelection behavior-only.

Use the wrapper in fixed and floating Storybook and website examples. The
floating website example fills its available width while retaining a capped
internal scroll region, uses compact equal-width content columns to avoid
horizontal overflow, reserves toolbar space, keeps the toolbar 16px from the
scrollport, and does not move the table when selection changes.

Keep the hidden production ShadCN registry compatible with the latest stable
package by requiring both a published import subpath and published component
metadata before emitting a block. Add public docs, exports, localized defaults,
the ShadCN route lock, the reviewed documentation and sandbox route inventories,
and a patch changeset.

Closes meta#5486.
Refs meta#6474.

**This diff was generated with AI assistance (Navi).** The implementation,
regression coverage, validation, and review-feedback updates were produced with
AI assistance. The human author reviewed and approved the changes.

*Crafted with care by Navi*

Tags: ai-generated

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval is waiting on a maintainer to provide or identify the governing spec for the new public TableSelectionToolbar / selectionState contract — including complete-clear behavior, the sm/muted and localized-label defaults, and the fixed and floating placement recipes — and for omitting blocks that depend on unreleased components from the latest registry. The current Table, Toolbar, and scrolling specs cover the adjacent mechanics, but they do not settle this new public addition, and the registry compatibility record is still draft.

Two implementation issues also need fixing:

  • The new latest-registry check drops existing released blocks. It compares componentsUsed against published component-entry names, but the three ChatDictation examples list ChatDictation and the NavHeadingMenu showcase lists NavHeadingMenuItem — neither is a component-entry name, even though both blocks import only published package paths. Please gate on the imported exports or correct those entries, and add a regression showing existing released blocks stay in the latest registry.
  • Activating "Unselect All" removes the toolbar and its focused button with no focus restoration, leaving keyboard focus on the document body. Please define and test where focus goes when clearing removes the toolbar.

Browser behavior was not independently rerun in this review.

[Automated review]

github-actions Bot added a commit that referenced this pull request Sep 28, 2026
@humbertovirtudes
humbertovirtudes merged commit d774400 into meta:main Sep 30, 2026
40 checks passed

This branch was successfully deployed

1 active deployment
Preview — ab4737a1 Deployed Sep 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Table selection: opt-in bulk-actions toolbar

3 participants