Building an Accessible, Sortable Data Table in React

Most dashboards ship a sortable table that works with a mouse and little else. Here are the specific details I use to make one that works with a keyboard and assistive technology, with the code from my Pulseboard dashboard.

6 min readBy Saad Ali KhanOct 2026
Building an Accessible, Sortable Data Table in React

Start with real table markup

A <table> with <th scope="col"> headers already gives screen readers row and column navigation. Replacing it with divs and then trying to rebuild that with ARIA is more work and usually worse. Add a caption that is hidden visually but announced:

<table className="w-full min-w-[640px] text-sm">
  <caption className="sr-only">Orders</caption>
  <thead>
    <tr>
      <th scope="col">Order</th>
      ...

Sortable headers: a button inside the th, plus aria-sort

Do not put a click handler on the <th> itself. Put a real <button> inside it so it is focusable and works with Enter and Space, and set aria-sort on the header so assistive tech announces the current sort:

const th = (k: SortKey, label: string) => (
  <th
    scope="col"
    aria-sort={sortKey === k ? (dir === "asc" ? "ascending" : "descending") : "none"}
  >
    <button type="button" onClick={() => onSort(k)}>
      {label} {sortKey === k ? (dir === "asc" ? "▲" : "▼") : ""}
    </button>
  </th>
);

The arrow is a visual cue only. The truth for screen readers is in aria-sort, so the two never disagree.

Label every filter, even the ones without visible labels

A search box with only a placeholder has no accessible name. If your design hides the label, use a visually hidden one:

<label className="sr-only" htmlFor="q">Search orders</label>
<input id="q" type="search" placeholder="Search customer or order ID" ... />

The same goes for the status and region selects. A placeholder is not a label.

Announce results without stealing focus

When the user types in the search box and the table shrinks, a sighted user sees it happen. A screen reader user hears nothing unless you tell them. A polite live region reports the new count without moving focus:

<span aria-live="polite">{sorted.length} orders · page {current + 1} of {pages}</span>

Do not rely on colour alone

Status badges are green, amber and red, but each one also contains its status as text (paid, pending, refunded). Someone who cannot distinguish the colours still gets the meaning.

Give the chart a text alternative

A chart drawn as SVG is just a picture to a screen reader. Give it a role and a label, and include the same data as hidden text:

<svg viewBox="0 0 100 48" role="img" aria-label={`Weekly revenue, ${data.length} weeks`}>
  ...
</svg>
<figcaption className="sr-only">
  {data.map((d) => `Week of ${d.label}: ${format(d.value)}`).join("; ")}
</figcaption>

Test the behaviour, not just the pixels

Accessible behaviour is easy to break by accident, so I test it. With Testing Library you can find the header by its role and assert the sort state changes:

const th = screen.getByRole("columnheader", { name: /Amount/ });
await userEvent.click(within(th).getByRole("button"));
expect(th).toHaveAttribute("aria-sort", "descending");
await userEvent.click(within(th).getByRole("button"));
expect(th).toHaveAttribute("aria-sort", "ascending");

What this does not cover

This checklist covers the structure and semantics, which is the part developers can fix in code. It is not a full accessibility audit. I have not run screen-reader testing on this demo, so treat it as a solid baseline and run your own assistive-technology checks before calling a product accessible.

See the working dashboard and its source in the Pulseboard case study.

Original article written by Saad Ali Khan. Code samples are illustrative and free to adapt in your own projects.

Want this done right in your project?

Send a short description and I'll reply by email with questions or a suggested approach.