gridcn2.0.0
Basic examples

Screen reader announcements example

Show the text that the grid live region reads after a check or a filter, with announceResults turned on.

The grid reads changes to a screen reader through one live region. In the demo, a line above the grid copies the last text of that region, so you can follow the announcements without a screen reader. The grid sets announceResults, so a filter also reads the row count.

Check rows with the markers or Ctrl+Shift+Space, or filter a column. The line below shows the text a screen reader hears from the grid's live region.

Row markers
Name
Role
Score
Silent Tiger
Viewer
4
Quick Lion
Viewer
89
Swift Wolf
Manager
80
Eager Lion
User
51
Eager Tiger
Viewer
83
Silent Wolf
User
15
Swift Lion
Viewer
62
Eager Lion
Manager
42
Eager Eagle
Editor
35
Bold Tiger
Editor
52
Bold Bear
User
28
Swift Wolf
Manager
9
Swift Bear
Viewer
45
Eager Wolf
Editor
44
Swift Eagle
Viewer
51
Quick Lion
Manager
28
Bold Wolf
Editor
76
Swift Eagle
Admin
26
Eager Eagle
Manager
70
Eager Bear
Editor
67
Silent Lion
Manager
89
Silent Tiger
Manager
40
Eager Tiger
Manager
82
Silent Lion
Admin
16
Bold Eagle
Admin
38
Bold Lion
Viewer
3
Quick Tiger
Viewer
41
Bold Eagle
Editor
10
Swift Tiger
Editor
6
Silent Lion
Viewer
42
pnpm dlx shadcn@latest add @gridcn/data-grid-announcements-demo

What the demo shows

  • A check or an uncheck with the row markers reads the number of checked rows, for example "3 rows checked".
  • A filter from the header filter reads the number of rows of the view, for example "42 rows". A filter that keeps the same rows stays quiet. A sort that changes the row order reads the count too. A view with zero rows reads "No results".
  • The region waits 500 ms after the last change, so a fast series of checks reads one count.
  • The live region carries the data-grid-live-region attribute. The demo watches it with a MutationObserver and hides its copy from screen readers with aria-hidden.

The grid prop turns on the result counts:

import { DataGrid, defineColumns } from "@/components/data-grid/data-grid";

type Row = { id: string; name: string };

const columns = defineColumns<Row>()([
  { id: "name", header: "Name", accessorKey: "name" },
]);

const rows: Row[] = [{ id: "1", name: "Ada" }];

export function AnnouncedGrid() {
  return (
    <DataGrid
      defaultData={rows}
      columns={columns}
      rowMarkers="checkbox"
      announceResults
    />
  );
}

On this page