Skip to content

fix: give sortable Table starter column headers a button role - #10996

Open
jsabutis wants to merge 1 commit into
adobe:mainfrom
jsabutis:fix/8502-sortable-column-header-role
Open

jsabutis wants to merge 1 commit into
adobe:mainfrom
jsabutis:fix/8502-sortable-column-header-role

Conversation

@jsabutis

Copy link
Copy Markdown
Contributor

Closes #8502

Summary

The Table starters wrap the column name in a Group with role="presentation" and tabIndex={-1}, so it can take focus separately from the ColumnResizer. A focusable element with a presentational role is announced with no role at all, so a screen reader user who lands on the name gets no cue that activating it changes the sort order.

Following the review on #10364, this drops Group rather than widening its role type. The name is now a plain div: role="button" when the column allows sorting, and no role when it does not, since a non sortable name does nothing when activated. tabIndex={-1} is unchanged in both cases, so focus still moves between the name and the resizer as before. Clicks and Enter still reach the column header's own press handling, so sorting works the same way.

Group was only supplying the focus ring state, so the focus ring moves to :focus-visible: &:focus-visible in the vanilla starter's Table.css, and focus-visible: classes in the Tailwind starter, matching the colours focusRing used and the same pattern Toast.tsx already uses there.

Changed: starters/docs/src/Table.tsx, starters/docs/src/Table.css, starters/tailwind/src/Table.tsx. Both are rendered by the React Aria Table docs. No package code changes.

AI use: AI tooling assisted with this change. I reviewed every line and can explain each decision.

📝 Test Instructions

  • yarn check-types: passes.
  • yarn oxfmt --check on the three changed files: passes. oxlint does not cover starters/.
  • A throwaway Jest test (not included, since the starters have no test suite) rendered a Table from each starter with one sortable and one plain column. With this change the sortable name has role button and accessible name "Name", the plain one has no role, and clicking or pressing Enter on the button calls onSortChange once. On main the same test fails: no element with role button is found.

To check manually: open the React Aria Table docs, sorting example. Arrow into a sortable header and onto its name: it is announced as a button, the focus ring shows, and Enter sorts. A non sortable column's name is not announced as a button.

Recording of the docs starter Table in Chromium, same keys on both sides: ArrowUp onto Name, Enter twice, ArrowRight onto Type, Enter. The box in the corner shows the focused element's role and name from Chrome's accessibility tree.

Before (main): the sortable name is generic.

Before: sortable column name has role generic

After: the sortable name is button, Type stays generic, the focus ring looks the same, and Enter still sorts.

After: sortable column name has role button

Side by side: before-after.mp4

Not yet checked: forced colors, RTL, Firefox, Safari, and the Tailwind starter in a browser.

Release impact

  • Only changes docs, tests, CI, or development tools. Nothing shipped to users changes.
  • Fixes a bug or improves existing code without changing how apps use it.
  • Adds a feature or API while keeping existing usage working.
  • May break existing usage or require changes in apps that use this code.

✅ PR Checklist

  • I followed the contributing guide.
  • I tested this change locally and included the results in Test Instructions, or explained why testing does not apply.
  • I understand and can explain every change in this PR. If I used AI assistance, I followed the AI contribution guidance.

🧢 Your Project

Nclusion

The Table starters wrap the column name in a Group with role="presentation"
and tabIndex={-1} so it can take focus apart from the ColumnResizer. A
focusable presentational element is announced with no role, so a screen
reader user has no cue that activating it changes the sort order.

Render a plain div instead, with role="button" when the column allows
sorting and no role otherwise. Group only supplied the focus ring state, so
the focus ring now uses :focus-visible.

Closes adobe#8502
@github-actions github-actions Bot added the Table label Nov 18, 2026

@snowystinger snowystinger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the change to the css file may be causing the CI failure

yarn check:starter-css
Hook starter CSS is out of date:
  Table.css
Run: yarn sync:starter-css

border-radius: var(--radius-sm);

&[data-focus-visible] {
&:focus-visible {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why?

{({allowsSorting, sortDirection}) => (
<div className="column-header">
<Group role="presentation" tabIndex={-1} className="column-name">
<div role={allowsSorting ? 'button' : undefined} tabIndex={-1} className="column-name">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Was there a reason you didn't do this?

Suggested change
<div role={allowsSorting ? 'button' : undefined} tabIndex={-1} className="column-name">
<div role={allowsSorting ? 'button' :'presentation'} tabIndex={-1} className="column-name">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RAC Table: column header text with tabindex should have role="button"

2 participants