Skip to content

docs(TableSelectionToolbar): a recipe for selecting every matching row across server pages - #10271

Merged
cixzhang merged 5 commits into
mainfrom
docs/table-select-all-matching-recipe
Nov 10, 2026
Merged

cixzhang merged 5 commits into
mainfrom
docs/table-select-all-matching-recipe

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Reader impact

People managing hundreds of records across server pages want to select every record that matches their filter, untick a few, and run one bulk action without opening every page. Product teams building that today have to work it out from the low-level selection hook alone. After this change, TableSelectionToolbar's docs and a Storybook recipe story show the complete flow on today's API:

  • "Select all 248 matching"
  • "All 248 matching selected"
  • "247 of 248 matching selected"

Source of truth

  • useTableSelection (getIsItemSelected, onSelectItem, onSelectAll, getIsAllSelected, getIsIndeterminate) and TableSelectionToolbar (selection, renderSelectionLabel, startContent) on main. No Core code changes.
  • The owner decision recorded here as component:TableSelectionToolbar DEC-1: the app keeps this selection. A Core model for it is decided together with Table's server-pagination contract, because both need a total that is not loaded. This PR makes no promise of a future API.

Correction

  • Missing guidance, now added:
    • The app keeps "every matching row minus exclusions" (or the rows picked one by one).
    • It feeds that model to useTableSelection.
    • It passes the toolbar its own selectedCount and a renderSelectionLabel.
  • The one stretch, documented: in this mode the toolbar's selectedKeys holds only the loaded rows, while the count comes from the app. A bulk action sends the server the query and the excluded ids, not a list of ids.

Evidence

  • TableSelection.stories.tsx → Select All Matching story. Its play test:

    1. selects the page;
    2. selects all 248 matching; the used offer stays as "Select only this page" and keeps focus, and a second Enter returns to the page selection (it never reaches Archive); a third Enter selects all 248 again;
    3. unticks one row (247 of 248);
    4. moves to a page that was never loaded, where the rows are already checked;
    5. clears.
  • Real Chrome (the PR's Vercel Storybook at 466a143, Chromium, 900×620), in light and dark mode the toolbar reads:

    1. "Select all 248 matching · 5 selected";
    2. "All 248 matching selected";
    3. "247 of 248 matching selected";
    4. on page 2, every row is checked.

    There were no page errors, and the colours match the existing toolbar and selected rows in both modes.

  • Focus after the offer (Chromium 155, built Storybook at this head): page selected → focus the offer → Enter: focus "Select only this page", toolbar "All 248 matching selected" → Enter: focus "Select all 248 matching", toolbar "5 selected". Archive never takes focus. The doc example uses the same button, so focus stays on it there too.

Follow-ups (tracked separately, not in this PR)

  • The docs example's useTableSelection call passes no getIsIndeterminate, so its header checkbox shows empty on a partly selected page; the story already passes one.
  • A one-line note that the recipe's English labels are the app's own copy, to localize with plural rules.

Scope

  • This PR changes documentation only, or names every necessary generated artifact.
  • Runtime, API, visual, and policy changes were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

  • pnpm check:knowledge, check:changesets; eslint on the story. Typecheck: CI's typecheck job is the check of record.
  • The story's play test runs in CI.

Writing rubric results

  • R1 narration: none. DEC-1 and the non-goal line state who owns what.
  • R2 research: none in the record. The options comparison lives in the owner's explainer, not here.
  • R3 evidence: no evidence cells changed.
  • R4 rejected alternatives: one, in DEC-1, one line.
  • R5 change references: none.
  • R6 open questions: none added.

…w across server pages

People managing many records across server pages can select every row
that matches their filter, untick a few, and run one bulk action. This
documents how an app builds that with today's API: it keeps "every
matching row minus exclusions" and passes the toolbar its own count and
label. A Storybook recipe story shows and tests the flow. The record
notes that the app owns this selection, and that a Core model is decided
with Table's server-pagination contract.
@vercel

vercel Bot commented Nov 6, 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 Nov 9, 2026 7:49pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 6, 2026
@astracat-bot

astracat-bot Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 9, 2026, 10:25 PM UTC

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · de60d76

Storybook · Sandbox · built from this PR's head

Current run: Heavy CI deferred: runs when marked ready and before merge. Lint, typecheck and any path-filtered checks ran on this push.


Generated by PR Enrichment workflow | View current CI run

@cixzhang

cixzhang commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 466a143

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 6, 2026

@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 waits on an engineering owner's decision on the new component:TableSelectionToolbar DEC-1, and the recipe needs two fixes.

Spec decision needed

  • DEC-1 and the new non-goal line decide that an app may pass the toolbar a selection it builds itself, with its own count and label and a selectedKeys that holds only the loaded rows, while the current record says the selection comes from useTableSelectionState. An engineering owner records the decision by commenting /approve-spec <full head SHA> on this pull request (the author may do so as an engineering owner), or asks for changes to DEC-1.

Blocking findings

  • "Select all 248 matching" and Archive render in the same button slot (TableSelection.stories.tsx lines 666-682 and the docs example at TableSelectionToolbar.doc.mjs lines 128-138), so after Enter or a click on the offer, focus stays on a button that now reads Archive and a second press archives every matching row, while Archive is missing whenever a page is fully selected; render the offer beside the actions instead.
  • The doc still tells builders to pass selectionState directly from useTableSelectionState (TableSelectionToolbar.doc.mjs lines 9, 15, 66 and 71), which the new example contradicts; qualify that guidance with the server-pages case.

CI has not run on this draft yet.

[Automated review]

astracat-bot[bot]
astracat-bot Bot previously requested changes Nov 6, 2026

@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.

The spec decision is settled: an engineering owner approved component:TableSelectionToolbar DEC-1 for this head. Two fixes to the recipe remain before it can be approved.

Blocking findings

  • "Select all 248 matching" and Archive render in the same button slot (apps/storybook/stories/TableSelection.stories.tsx lines 666-682, copied in TableSelectionToolbar.doc.mjs lines 128-138), so after Enter focus stays on the same button, now labelled Archive, and a second Enter or a double-click on its start runs Archive on every matching row; render the offer beside the actions instead, which also keeps Archive available while a page is fully selected.
  • TableSelectionToolbar.doc.mjs still tells builders to pass selectionState straight from useTableSelectionState (lines 9, 15, 66, 71, 152 and 155), which the new example contradicts; qualify that guidance with the server-pages case DEC-1 describes.

Otherwise the story's flow works as described: the matching labels, the unticked-row count and the pre-checked rows on pages that never loaded, in light and dark mode.

[Automated review]

@cixzhang
cixzhang marked this pull request as ready for review November 6, 2026 13:29
…ctions

The offer turned into Archive in place, so a second press on it archived
every matching row. It now renders beside the actions, and the story
moves focus to Archive once the offer is used. The toolbar guidance names
the app-built selection state for selections across server pages.
@cixzhang

cixzhang commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 3b52483

astracat-bot[bot]
astracat-bot Bot previously requested changes Nov 6, 2026

@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.

The select-all-matching recipe works as described and its owner decision is settled: an engineering owner approved component:TableSelectionToolbar DEC-1 for this head. Two focus problems in the recipe need fixing before it can be approved.

  • In the story, using "Select all 248 matching" moves focus to Archive (apps/storybook/stories/TableSelection.stories.tsx lines 684-692, asserted at line 739), so a second Enter runs Archive with every matching row selected; leave focus where a repeated Enter cannot start a bulk action, for example by keeping the used offer mounted as a non-destructive command, and update the play test.
  • In the TableSelectionToolbar.doc.mjs example, the offer only calls setIsAllMatching(true) (line 138), so the focused button unmounts and focus falls to the page body; give the example the same focus handling as the story once that handling no longer lands on Archive.

Mouse double-clicks are already safe, and the matching labels, the unticked-row count and the pre-checked rows on pages that never loaded render as described in light and dark mode.

[Automated review]

… undo, so focus never reaches Archive

After "Select all N matching", focus moved to Archive, so a second Enter
archived every matching row, and the doc example dropped focus to the
page body. The offer now stays in its place as "Select only this page",
which undoes it: focus stays on the same button, and a repeated Enter only
toggles the scope. The play test presses Enter twice and checks focus.
@cixzhang

cixzhang commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 9b9870f

astracat-bot[bot]
astracat-bot Bot previously requested changes Nov 7, 2026

@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.

The double-press problem is fixed: the used offer now stays in place as "Select only this page" and keeps focus, and component:TableSelectionToolbar DEC-1 is approved by an engineering owner for this head. One fix to the recipe remains before this can be approved.

  • "Select only this page" keeps only the page's checked rows while the offer renders only when isAllMatching || isPageSelected, so after unticking a row on the current page it unmounts while focused and focus drops to the page, and after unticking the whole page it leaves nothing selected and removes the toolbar (apps/storybook/stories/TableSelection.stories.tsx line 686 with line 672, and packages/core/src/Table/TableSelectionToolbar.doc.mjs line 145 with line 134); selecting every row on the page (new Set(rows.map(row => row.id))) keeps the label true and the button mounted, and a play step that unticks a row first would cover it.

[Automated review]

@humbertovirtudes humbertovirtudes 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.

Requesting changes for one remaining focus issue in the recipe. The earlier findings are resolved: the offer now renders beside Archive, the used offer stays mounted as "Select only this page" and keeps focus, the doc guidance is qualified for the server-pages case, and component:TableSelectionToolbar DEC-1 is approved for this head.

Blocking

  • apps/storybook/stories/TableSelection.stories.tsx:686 (with :603 and :672), and TableSelectionToolbar.doc.mjs:145 (with :98 and :134): in all-matching mode, "Select only this page" keeps only the page's currently checked rows, but the offer renders only while isAllMatching || isPageSelected, and isPageSelected is rows.every(isSelected). If a row on the page was unticked first, pressing the button unmounts it while it holds focus, so keyboard focus falls to the page body. If the whole page was unticked, the selection becomes empty and the toolbar disappears. Selecting every row on the page (new Set(rows.map(row => row.id)), or pageRows in the doc example) matches the label and keeps the button mounted. Please add a play step that unticks a row before using the undo, so this path is covered.

Non-blocking

  • Heavy CI is deferred at this head, so the SelectAllMatching play test has not run in CI yet. Worth confirming once it runs.
  • The recipe builds its labels by string concatenation in English. A one-line note that the app owns this copy and should localize it with plural rules would help readers who copy it.

Checked at 9b9870f: merges cleanly with current main; lint, typecheck and smoke-test pass; build, test and docsite-test stop at the heavy-CI deferral gate rather than on a code failure.

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 8, 2026
…e page

With a row on the page unticked, the undo kept only the checked rows, so
the offer unmounted under focus, and with the whole page unticked it left
nothing selected. It now selects every row on the page, which matches its
label and keeps the focused button mounted. The play test unticks a row
first.
@cixzhang

cixzhang commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec a445552

@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.

No blocking findings remain at this head: "Select only this page" now selects every row on the page in both the story and the docs example, so the button keeps focus, and the play test covers a page with an unticked row. component:TableSelectionToolbar DEC-1 is approved by an engineering owner for this head.

Approval still waits on @humbertovirtudes: their change request from the previous revision was dismissed by the author rather than by them, so it needs their re-review on this head (an approval, or a note saying what remains).

  • Non-blocking: the docs example's useTableSelection call still passes no getIsIndeterminate, so its header checkbox shows empty on a partly selected page; the story already passes one.
  • Heavy CI is deferred at this head, so the story's play test has not run in CI yet.

[Automated review]

@cixzhang
cixzhang dismissed stale reviews from humbertovirtudes, astracat-bot[bot], astracat-bot[bot], and astracat-bot[bot] November 8, 2026 07:01

(Posted by Cindy's agent.) Dismissing as addressed at head a445552, with thanks. The blocking focus issue is fixed: "Select only this page" now selects every row on the page (story: picked = new Set(rows.map(row => row.id)); doc example: setPicked(new Set(pageRows.map(row => row.id)))), so the offer stays mounted under focus and an unticked page no longer clears the selection. The story's play test now unticks a row, presses the offer, and checks "5 selected" with focus kept on "Select all 248 matching". The earlier automated findings (offer slot, focus after select-all, double press) are fixed at this head, and the latest automated review here reports no blocking findings. The non-blocking notes (heavy CI at merge, a localization note, an optional getIsIndeterminate in the doc example) are left for a follow-up.

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 8, 2026

@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.

Approved. An engineering owner approved component:TableSelectionToolbar DEC-1 for this head, the select-all-matching recipe behaves as described, and the earlier change request is addressed: "Select only this page" now selects the whole page and the play test covers a page with an unticked row. CI has run on this head and passes.

Optional follow-ups, none blocking:

  • The docs example's useTableSelection call passes neither getIsIndeterminate nor getRowLabel, so a copy shows an empty header checkbox on a partly selected page and names every row checkbox "Select row"; the story already passes both.
  • DEC-1's rejected line ("before the server-pagination contract exists") states temporary status; "decided apart from Table's server-pagination contract" keeps the decision without it.
  • No CI job runs the SelectAllMatching play function yet (it passes when run); adding it to the story play guard's targets would make it a required check.

[Automated review]

Comment on lines +101 to +107
const selectionPlugin = useTableSelection({
getIsItemSelected: isSelected,
// setRows adds to or removes from excluded in all mode, picked otherwise.
onSelectItem: ({item, isSelected}) => setRows([item], isSelected),
onSelectAll: ({isAllSelected}) => setRows(pageRows, isAllSelected),
getIsAllSelected: () => isPageSelected,
});

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.

Non-blocking: this call passes neither getIsIndeterminate nor getRowLabel, so a copy shows an empty header checkbox on a partly selected page and names every row checkbox "Select row". The story passes both; for example:

getIsIndeterminate: () => !isPageSelected && pageRows.some(isSelected),
getRowLabel: row => row.name,

Comment on lines +173 to +174
Rejected: an all-matching mode in `useTableSelectionState` before the
server-pagination contract exists.

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.

Non-blocking: "before the server-pagination contract exists" states temporary project status. Suggested: "Rejected: an all-matching mode in useTableSelectionState decided apart from Table's server-pagination contract."

@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.

Approved pending CI: build, test and docsite-test have not run on this head yet and run in the pre-merge re-run. An engineering owner approved component:TableSelectionToolbar DEC-1 for this head, the select-all-matching recipe works as described in the story and the docs example, and the earlier change request is addressed: "Select only this page" selects the whole page, and the play test covers a page with an unticked row. Lint, typecheck and the smoke test pass on this head.

Optional follow-ups, none blocking:

  • The docs example's useTableSelection call passes neither getIsIndeterminate nor getRowLabel, so a copy shows an empty header checkbox on a partly selected page and announces every row checkbox as "Select row"; the story already passes both.
  • DEC-1's Rejected line ("before the server-pagination contract exists") states temporary status; "decided apart from Table's server-pagination contract" keeps the decision without it.

[Automated review]

@cixzhang

cixzhang commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec de60d76

@cixzhang
cixzhang marked this pull request as draft November 10, 2026 00:34
@cixzhang
cixzhang marked this pull request as ready for review November 10, 2026 00:34
@cixzhang
cixzhang merged commit a0a09f9 into main Nov 10, 2026
127 of 131 checks passed
@github-actions
github-actions Bot deleted the docs/table-select-all-matching-recipe branch November 10, 2026 06:04
cixzhang added a commit that referenced this pull request Nov 12, 2026
failingSpecs no longer waits after its fourth and last try, so a log that keeps
answering 5xx gives up after 30 s of waits, and a test pins four server errors
in a row. This also corrects the earlier commit's wording: the three pull
requests that now replay a narrow selection (#9672, #10271, #10944) are ones
whose story was their only full-suite trigger, not ones that change only
stories. Their stories are Drawer, TableSelection and Avatar; Button's specs run
because those stories import Button.
cixzhang added a commit that referenced this pull request Nov 12, 2026
… retries a server error (#11317)

* ci: the selection replay record covers the story rule; a log download retries a server error

The record is regenerated with the Chromium lane's story rule (#11250). Every
verdict matches the earlier record: 144 no failure, 4 caught, 4 reviewed, 1 out
of scope. Three pull requests that change only stories now replay a narrow
selection with no failure (#9672, #10271, #10944). GitHub's job-log endpoint
answers 502 now and then, so failingSpecs tries a server error again, up to
four times, before it calls a log unreadable.

* Merge remote-tracking branch 'origin/main' into ci/replay-story-rule

* ci: a log download waits only between tries, not after the last

failingSpecs no longer waits after its fourth and last try, so a log that keeps
answering 5xx gives up after 30 s of waits, and a test pins four server errors
in a row. This also corrects the earlier commit's wording: the three pull
requests that now replay a narrow selection (#9672, #10271, #10944) are ones
whose story was their only full-suite trigger, not ones that change only
stories. Their stories are Drawer, TableSelection and Avatar; Button's specs run
because those stories import Button.

This branch was successfully deployed

1 active deployment
Preview — de60d763 Deployed Nov 9, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants