DataGrid
AlphaAn 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
| Prop | Type | Default | Description |
|---|---|---|---|
data* | any[] | - | Array of row data objects |
columns* | DataGridColumnDef[] | - | Column definitions |
mode | 'default' | 'editable' | 'default' | Enable inline cell editing |
sortDirection | DataGridSortDirection | - | Controlled sort state |
onSortChange | (key: string, direction: DataGridSortDirection) => void | - | Called when sort changes |
Sub-components
DataGrid.Toolbar
| Prop | Type | Default | Description |
|---|---|---|---|
children* | ReactNode | - | Toolbar content (buttons, filters) |
Keyboard Interactions
Accessibility
All keyboard interactions follow WAI-ARIA best practices and work without any additional configuration.
| Key | Action |
|---|---|
| ArrowRight / ArrowLeft | Move focus between cells in a row |
| ArrowDown / ArrowUp | Move focus between rows |
| Home / End | Move to first/last cell in the row |
| Ctrl+Home / Ctrl+End | Move to first/last cell in the grid |
| Enter | Begin editing the focused cell (editable mode) |
| Escape | Cancel editing and restore previous value |
| Tab | Exit the grid to the next focusable element |