DataGrid

Alpha

An advanced, interactive data grid with cell-level keyboard navigation (ARIA grid pattern), sorting, inline editing, and toolbar support.

Import

import { DataGrid } from "@compa11y/react";

Usage

Example.tsx
import { DataGrid, Button } from "@compa11y/react";

const columns = [
  { key: "name", header: "Name", sortable: true },
  { key: "email", header: "Email", sortable: true },
  { key: "role", header: "Role" },
];

const data = [
  { name: "Alice Johnson", email: "alice@example.com", role: "Admin" },
  { name: "Bob Smith", email: "bob@example.com", role: "Editor" },
  { name: "Carol White", email: "carol@example.com", role: "Viewer" },
];

function TeamGrid() {
  return (
    <DataGrid data={data} columns={columns}>
      <DataGrid.Toolbar>
        <Button variant="outline" size="sm">Export</Button>
        <Button size="sm">Add Member</Button>
      </DataGrid.Toolbar>
    </DataGrid>
  );
}

Features

  • role='grid' with ARIA grid navigation pattern
  • Cell-level focus with Arrow keys, Home, End, Ctrl+Home, Ctrl+End
  • Sortable columns with aria-sort
  • Inline cell editing with Enter to start, Escape to cancel
  • Toolbar slot for actions
  • Column resizing with keyboard support
  • Screen reader announcements for sort and edit operations

Props

DataGrid component props
PropTypeDefaultDescription
data*any[]-Array of row data objects
columns*DataGridColumnDef[]-Column definitions
mode'default' | 'editable''default'Enable inline cell editing
sortDirectionDataGridSortDirection-Controlled sort state
onSortChange(key: string, direction: DataGridSortDirection) => void-Called when sort changes

Sub-components

DataGrid.Toolbar

DataGrid.Toolbar props
PropTypeDefaultDescription
children*ReactNode-Toolbar content (buttons, filters)

Keyboard Interactions

Accessibility
All keyboard interactions follow WAI-ARIA best practices and work without any additional configuration.
Keyboard shortcuts for DataGrid
KeyAction
ArrowRight / ArrowLeftMove focus between cells in a row
ArrowDown / ArrowUpMove focus between rows
Home / EndMove to first/last cell in the row
Ctrl+Home / Ctrl+EndMove to first/last cell in the grid
EnterBegin editing the focused cell (editable mode)
EscapeCancel editing and restore previous value
TabExit the grid to the next focusable element