Skip to content

DataTable: Add "SR only" text for sortable columns #6109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 23, 2025

Conversation

TylerJDev
Copy link
Member

@TylerJDev TylerJDev commented May 21, 2025

Add visually hidden text to sortable DataTable column buttons when not sorted.

Changelog

Changed

  • Added visually hidden text to sortable column buttons

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

Merge checklist

@github-actions github-actions bot added staff Author is a staff member integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels May 21, 2025
Copy link
Contributor

👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks!

Copy link
Contributor

github-actions bot commented May 21, 2025

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 94.42 KB (0%)
packages/react/dist/browser.umd.js 94.48 KB (0%)

Copy link

changeset-bot bot commented May 22, 2025

🦋 Changeset detected

Latest commit: 4d81bbd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

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

@TylerJDev TylerJDev requested a review from joshblack May 22, 2025 13:58
@TylerJDev TylerJDev marked this pull request as ready for review May 22, 2025 13:58
@Copilot Copilot AI review requested due to automatic review settings May 22, 2025 13:58
@TylerJDev TylerJDev requested a review from a team as a code owner May 22, 2025 13:58
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This patch adds visually hidden text to sortable DataTable column headers (when unsorted) to improve screen-reader context and updates tests to match the new accessible names.

  • Injects <VisuallyHidden>sort ascending</VisuallyHidden> for unsorted columns
  • Updates DataTable.test.tsx to look for the new accessible name
  • Adds a changeset entry for a patch release

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/react/src/DataTable/Table.tsx Wraps the ascending icon in a fragment and adds hidden text for unsorted state
packages/react/src/DataTable/tests/DataTable.test.tsx Adjusts getSortHeader calls to include the hidden text in the accessible name
.changeset/dry-breads-attack.md Adds a patch-level changeset noting the accessibility update
Comments suppressed due to low confidence (2)

packages/react/src/DataTable/Table.tsx:162

  • Ensure that VisuallyHidden is imported at the top of this file; without the import, the component reference will break the build.
{direction === SortDirection.NONE ? <VisuallyHidden>sort ascending</VisuallyHidden> : null}

.changeset/dry-breads-attack.md:5

  • [nitpick] Consider adding or updating a Storybook story or a snippet in the docs to demonstrate the new screen-reader-only text in action for accessibility previews.
DataTable: Add visually hidden text to sortable DataTable column buttons

@@ -826,7 +826,7 @@ describe('DataTable', () => {

// When interacting with Column B, sort order should reset to ASC
await user.click(screen.getByText('Column B'))
expect(getSortHeader('Column A')).not.toHaveAttribute('aria-sort')
expect(getSortHeader('Column A sort ascending')).not.toHaveAttribute('aria-sort')
Copy link
Preview

Copilot AI May 22, 2025

Choose a reason for hiding this comment

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

[nitpick] This assertion now ties the test to the exact hidden text string, which could be brittle; consider using a regex or querying by part of the name (e.g., /Column A.*ascending/) to make the test less coupled to implementation details.

Suggested change
expect(getSortHeader('Column A sort ascending')).not.toHaveAttribute('aria-sort')
expect(getSortHeader(/Column A.*ascending/)).not.toHaveAttribute('aria-sort')

Copilot uses AI. Check for mistakes.

@TylerJDev TylerJDev added this pull request to the merge queue May 23, 2025
Merged via the queue into main with commit f7471f8 May 23, 2025
36 checks passed
@TylerJDev TylerJDev deleted the add-sr-text-for-data-table-sort branch May 23, 2025 15:08
@primer primer bot mentioned this pull request May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm staff Author is a staff member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants