Repository navigation
DataTable: announce selection changes independently of bulk actions - #8689
rickyzhangca wants to merge 9 commits into
Conversation
|
🦋 Changeset detectedLatest commit: 8d8424f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
🟡 Changes recommended
Selection changes in hidden, still-mounted tables can now trigger announcements because the new effect lacks the previous visibility guard, requiring a guard and regression test.
1 open issue
What changed in this PR
This PR moves DataTable selection announcements out of the bulk-action toolbar so selection counts and clearing are announced even without bulk actions.
Changes:
- Adds delayed selection announcements while suppressing initial, duplicate, and superseded messages.
- Hides inactive toolbar rows from the accessibility tree while preserving focus recovery.
- Adds announcement and keyboard tests, formatter documentation, and a patch changeset.
| File | Description |
|---|---|
packages/react/src/DataTable/TableSelectionAnnouncementContext.ts |
Shares the count formatter and announcement ownership context. |
packages/react/src/DataTable/TableBulkActions.tsx |
Avoids duplicate announcements within DataTable. |
packages/react/src/DataTable/DataTable.tsx |
Handles selection announcements and inactive toolbar accessibility. |
packages/react/src/DataTable/DataTable.docs.json |
Clarifies formatter support without bulk actions. |
packages/react/src/DataTable/__tests__/DataTableAnnouncements.test.tsx |
Covers announcement timing, localization, cancellation, and focus recovery. |
e2e/components/DataTableAnnouncements.test.ts |
Checks toolbar accessibility and keyboard focus recovery. |
.changeset/quiet-table-selection.md |
Documents the accessibility changes for a patch release. |
Review effort: Balanced
|
One or more custom setup steps configured for this repository failed during this Copilot code review run: Setup steps run before each review. If the review above is missing context, or no review was posted at all, the failing step above may be the cause. See the workflow run for failure details, fix your setup steps configuration, and re-request a review. Note You can configure setup steps for Copilot code review separately from Copilot cloud agent with a |
Keep initial selection silent, coalesce count changes, and exclude inactive bulk actions from the accessible table without removing focus recovery. Add browser regressions and document the outstanding shared live-region AT validation.
c07552b to
e57fe4a
Compare
Co-authored-by: Ricky Zhang <rickyzhangca@github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
|
||
| const bulkActions = bulkActionsRef.current | ||
| if (bulkActions) { | ||
| const observer = new MutationObserver(() => updateAnnouncement(false)) |
There was a problem hiding this comment.
@rickyzhangca This pattern seems similar to what we do in some of our other live region components. Is there a chance we could use one of those for this use-case or not really?
There was a problem hiding this comment.
the extra logic cancels a pending announcement if bulk actions disappear without a selection change which is something our current announcement system does not support
There was a problem hiding this comment.
it makes sense to leave it as a separate behaviour change and do a follow up improvement on existing live region
Keep announcement delivery in the existing live-region component and leave toolbar-only cancellation behavior out of scope. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Ignore hidden selection announcements when determining the last table content, preserving header spacing and pagination styling. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
| const actions = bulkActionsRef.current?.querySelector(`.${classes.Actions}`) | ||
| // eslint-disable-next-line react-you-might-not-need-an-effect/no-derived-state -- Action availability is only known after commit. | ||
| setMessage( | ||
| getSelectionAnnouncement({ | ||
| selectedCount, | ||
| bulkActionsAvailable: Boolean(actions && (actions.children.length > 0 || actions.textContent.trim())), | ||
| }), |
There was a problem hiding this comment.
The AriaStatus component will read its text content so could wrap it around the Actions selector or could use a new node directly with the text so that you don't have to synchronize with effects or anything 👀
Hope that makes sense, let me know if I'm making things more complicated here! The AriaStatus component is intended for stuff like this (like deduplicating announcements, making announcements when things change) but we could also extend that behavior into hooks or something else if that's easier to use here.
There was a problem hiding this comment.
yea not the best shape, we couldn't AriaStatus directly cuz it will read button text like "Apply" while we want to announce things like “1 row selected, additional bulk actions available”/“Selection cleared”
There was a problem hiding this comment.
extracted into a hook! i think it might be useful for select panel and autocomplete later on as well
added useAnnounce.ts, and let Announce.tsx use it instead
Share live-region visibility, deduplication, delay, and cleanup logic between Announce and DataTable without extra DOM nodes or state. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Keep the existing global announcement options unchanged when sharing announcement behavior through the internal hook. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ication Cancel pending announcements and clear deduplication state when updates occur while hidden, while keeping unmount cleanup scoped to pending timers so StrictMode remounts preserve initial deduplication. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Integration test results from github/github-ui PR:
CI check runs linting, type checking, and unit tests. Check the workflow logs for specific failures. Need help? If you believe this failure is unrelated to your changes, please reach out to the Primer team for assistance. |

Partially addresses github/primer#7342, github/primer#7343, and github/primer#7344.
Move selection announcements out of the bulk toolbar so every selection-enabled DataTable can announce counts and clearing. Separate live announcement localization from visible toolbar count localization.
Following review, extract the shared live-region announcement behavior (visibility checks, deduplication, delay handling, and unmount cleanup) from
Announceinto an internaluseAnnouncehook and use it directly in DataTable. DataTable only generates the announcement when the selected count changes, using the committed toolbar content to determine bulk-action availability without rendering an extra hidden DOM node or state cascade. Enhanced cancellation when toolbar content changes without a selection change remains out of scope.Changelog
New
getSelectionAnnouncement({selectedCount, bulkActionsAvailable})and exportDataTableSelectionAnnouncementContext.Changed
1 row selected,N rows selected, andSelection cleared, with the bulk-actions suffix only when actions render.useAnnouncebetweenAnnounceandDataTable, keeping initial selection silent and preserving live-region delay, deduplication, visibility checks, and unmount cleanup.bulkActionsProps.getSelectedCountLabelresponsible for the visible toolbar count and standaloneTable.BulkActionsbehavior.Removed
Rollout strategy
Integration/API reconciliation is tracked in github/primer#7348.
Testing & Reviewing
Local validation of this update:
npm run buildnpm test -- --runVITEST_FAIL_ON_CONSOLE=true npx vitest run --project '@primer/react' useAnnounce live-region DataTableSelection DataTableBulkActionsSTORYBOOK_URL=http://localhost:6006 npx playwright test e2e/components/DataTableAnnouncements.test.tsnpm run type-checknpm run lintnpm run lint:cssnpm run lint:react-compiler -w @primer/reactnpm run format:diffnpm run test:classname-coveragegit diff --checkCoverage retains initial-render silence, controlled and uncontrolled selection, rapid-update timing, custom-message deduplication, hidden ancestors, actual rendered bulk-action content, unmount cleanup, table corner/pagination layout, and keyboard focus recovery. Tests no longer require canceling a pending message solely because toolbar content changes.
Historical before/after screenshots, accessible trees, and live-region evidence remain available for the earlier implementation checkpoint; the recorded announcement wording predates the formatter changes. No evidence files are included in this PR.
github/github-ui#44600 passed integration CI, VRT, and Projects for the previous head (
7ef8e4fb5). Those results do not validate this new head.Manual VoiceOver/Safari, NVDA, and JAWS testing remains pending. Automated browser checks do not establish a fix for the historical VoiceOver delivery failure in github/primer#7342.