# Accessibility and localization

> The ARIA patterns and keyboard map of PivotTable, PivotFieldList, PivotAxisBar, PivotToolbar and the pivot dialogs, the localeText catalog, number and date formatting per locale, and right-to-left layouts.

Canonical: https://salmonui.dev/docs/pivot-table/accessibility

Every pivot part is a WAI-ARIA pattern with a keyboard path for each
pointer action, including drag and drop. The parts are audited with axe in
light, dark and right-to-left layouts.

## ARIA patterns

| Part | Pattern |
| --- | --- |
| `PivotTable`, compact layout | `treegrid`: member rows carry `aria-level` and `aria-expanded`; stacked column headers use `aria-colspan`; row headers are `rowheader`s and value cells `gridcell`s. The server renders a `grid` and the client upgrades it to `treegrid` after hydration, so the server HTML is valid without tree attributes. |
| `PivotTable`, tabular layout | `grid` with one pinned `rowheader` column per row field; drill toggles are buttons with `aria-expanded`. |
| `PivotFieldList` | A `group` holding the field `listbox` (multi-select) and one `listbox` per axis (Filters, Columns, Rows, Values). |
| `PivotAxisBar` | One `toolbar` per axis with a button per field. |
| `PivotToolbar` | `toolbar` with menu buttons (`aria-haspopup="menu"`) and toggles (`aria-pressed`). |
| Field menu | `menu` with `menuitem`s and submenus, opened from the field button. |
| Field list popup, member editor, calculated field, number and conditional formatting, grouping, drill through | Modal `dialog`s: focus moves in, Tab stays inside, Escape closes and focus returns to the control that opened the dialog. The member editor holds a `searchbox` and a checkbox `listbox`; the formula field reports errors through `role="alert"`; drill through holds a `DataGrid`. |
| Loading | `aria-busy` on the root and a `role="status"` message while the pivot computes. |

## Keyboard map

Inside the table, the [Data Grid keyboard map](https://salmonui.dev/docs/data-grid/accessibility)
applies (arrows, Home / End, Page Up / Page Down, Tab out). On top of it:

| Where | Key | Action |
| --- | --- | --- |
| Member row or column header | Enter or Space | Drill down or up |
| Table | Ctrl+ArrowDown / Ctrl+ArrowUp (Cmd on macOS) | Expand or collapse every row member |
| Value cell | Enter | Open drill through (when `drillThrough` is on) |
| Toolbar, axis bar | ArrowLeft / ArrowRight, Home, End | Move between buttons (one Tab stop per toolbar; mirrored in RTL) |
| Field list axis | ArrowUp / ArrowDown, Home, End | Move between fields |
| Field button (list or bar) | Enter, Shift+F10 or the context menu key | Open the field menu (sort, filter, aggregate, "Move to" an axis, remove) |
| Field button on an axis | Alt+ArrowUp / Alt+ArrowDown | Move the field one step inside its axis; focus follows it |
| Field button on an axis | Delete or Backspace | Remove the field from the report |
| Field list | Space | Check or uncheck the field |
| Menu | Arrows, Enter, Escape | Navigate, run, close (focus returns to the field button) |
| Dialog | Tab, Escape | Move inside the dialog, close it |

The "Move to" menu, Alt+Arrow and Delete are the keyboard alternative to
dragging fields between axes. On touch screens the same menu replaces the
drag gesture.

## Text and formatting

Every visible and assistive string comes from one plain-JSON catalog.
`localeText` overrides any key; `{param}` placeholders are substituted:

```tsx
import { PivotTable, PIVOT_DEFAULT_LOCALE_TEXT, type PivotLocaleText } from '@salmonui/pivot-table';

const de: PivotLocaleText = {
  grandTotal: 'Gesamtergebnis',
  subtotal: '{label} Ergebnis',
  expand: '{label} erweitern',
  collapse: '{label} reduzieren',
  rows: 'Zeilen',
  columns: 'Spalten',
  values: 'Werte',
  filters: 'Filter',
};

<PivotTable pivot={pivot} localeText={de} />
<PivotFieldList pivot={pivot} localeText={de} />
```

Pass the same `localeText` to `PivotFieldList`, `PivotAxisBar` and
`PivotToolbar` when you render them on their own; inside `PivotTable` the
axis bar, toolbar and dialogs inherit it. `PIVOT_DEFAULT_LOCALE_TEXT` lists
every key with its English default.

Numbers, dates and member sorting follow `locale` on `usePivot()` (or
`PivotTable`), through `Intl`; measure formats (`formats`) are `Intl`
options, so currency and grouping separators come from the locale:

```tsx
const pivot = usePivot({ data, fields, defaultPivotModel: model, locale: 'de-DE' });
```

## Right to left

Set `dir="rtl"` on the page or a container. The pivot styles use logical
properties only, so the row headers move to the right, the toolbars and
the axis bar mirror their arrow keys, and the dialogs, menus and the field
list follow the inherited direction. There is no RTL prop.

### Live demo: Keyboard, localization and right to left

Live demo: https://salmonui.dev/demos/pivot-table/pivot-table-accessibility

The treegrid, axis bar toolbars, field list and dialogs by keyboard, localeText with an Intl locale, right-to-left layout, and full-screen sheets on small screens.

`Demo.tsx`:

```tsx
'use client';

import { useState } from 'react';
import { PivotTable, type PivotFieldDefinition, type PivotLocaleText, type PivotModelInput } from '@salmonui/pivot-table';
import { Checkbox } from '@salmonui/inputs/checkbox';

type Sale = { region: string; country: string; year: string; amount: number };

const COUNTRIES: Record<string, string[]> = { Asia: ['Japan', 'India'], Europe: ['France', 'Germany'], Americas: ['Brazil', 'Canada'] };

function makeSales(): Sale[] {
  const rows: Sale[] = [];
  let n = 0;
  for (const [region, countries] of Object.entries(COUNTRIES)) {
    for (const country of countries) {
      for (const year of ['2025', '2026']) {
        for (let k = 0; k < 3; k++) {
          n++;
          rows.push({ region, country, year, amount: ((n * 613) % 2400) + 300 });
        }
      }
    }
  }
  return rows;
}

const SALES = makeSales();

// Field captions per language (the headers, the axis bar and the field list).
const FIELDS: PivotFieldDefinition<Sale>[] = [
  { field: 'region', caption: 'Region', type: 'string' },
  { field: 'country', caption: 'Country', type: 'string' },
  { field: 'year', caption: 'Year', type: 'string' },
  { field: 'amount', caption: 'Amount', type: 'number' },
];
const FRENCH_FIELDS: PivotFieldDefinition<Sale>[] = [
  { field: 'region', caption: 'Région', type: 'string' },
  { field: 'country', caption: 'Pays', type: 'string' },
  { field: 'year', caption: 'Année', type: 'string' },
  { field: 'amount', caption: 'Montant', type: 'number' },
];

const MODEL: PivotModelInput = {
  rows: [{ field: 'region' }, { field: 'country' }],
  columns: [{ field: 'year' }],
  values: [{ field: 'amount', aggregate: 'sum' }],
  formats: { amount: { number: { style: 'currency', currency: 'EUR', maximumFractionDigits: 0 } } },
};

// A partial French catalog: keys left out keep their English default.
const FRENCH: PivotLocaleText = {
  rowLabels: 'Étiquettes de lignes',
  grandTotal: 'Total général',
  subtotal: 'Total {label}',
  expand: 'Développer {label}',
  collapse: 'Réduire {label}',
  fieldList: 'Liste des champs',
  fields: 'Champs',
  searchFields: 'Rechercher des champs',
  rows: 'Lignes',
  columns: 'Colonnes',
  values: 'Valeurs',
  filters: 'Filtres',
  dropHere: 'Déposez un champ ici',
  apply: 'Appliquer',
  cancel: 'Annuler',
  close: 'Fermer',
  sortAsc: 'Tri croissant',
  sortDesc: 'Tri décroissant',
  filter: 'Filtrer',
  toolbar: "Barre d'outils du tableau croisé",
  totals: 'Totaux',
  export: 'Exporter',
  expandAll: 'Tout développer',
  collapseAll: 'Tout réduire',
};

/** Keyboard and ARIA semantics, localeText with an Intl locale, right to left, and adaptive sheets on small screens. */
export default function PivotTableAccessibilityDemo() {
  const [french, setFrench] = useState(false);
  const [rtl, setRtl] = useState(false);
  return (
    <div>
      <div className="demo-toolbar" role="group" aria-label="Language and direction">
        <Checkbox checked={french} onCheckedChange={(checked) => setFrench(checked)}>
          French text and fr-FR numbers
        </Checkbox>
        <Checkbox checked={rtl} onCheckedChange={(checked) => setRtl(checked)}>
          Right to left
        </Checkbox>
      </div>
      <div dir={rtl ? 'rtl' : 'ltr'}>
        <PivotTable<Sale>
          // The locale is read when the store is created: switching it remounts the table.
          key={french ? 'fr' : 'en'}
          data={SALES}
          fields={french ? FRENCH_FIELDS : FIELDS}
          defaultPivotModel={MODEL}
          locale={french ? 'fr-FR' : 'en-US'}
          {...(french ? { localeText: FRENCH } : {})}
          axisBar
          toolbar={['fieldList', 'totals', 'expandAll', 'collapseAll']}
          fieldList="popup"
          drillThrough
          height={300}
          aria-label={french ? 'Ventes par région' : 'Sales by region'}
        />
      </div>
      <p className="demo-status">
        Tab into the table, move with the arrow keys, press Enter on a row header to drill or on a value cell for its raw rows. On the axis bar, Enter opens a field menu
        with "Move to". Narrow the window below 640 px and open the field list: it becomes a full-screen sheet.
      </p>
    </div>
  );
}
```
