add-aria-to-table
v1.0.6
Published
Add ARIA roles to an HTML table and the child elements inside of it.
Downloads
478
Maintainers
Readme
Adding ARIA Roles to a Table
Adds or re-adds ARIA roles to an HTML table and its child elements. Intended to re-add the ARIA to a table that has been made responsive by CSS.
ARIA Roles
The roles that are added to each type of table element (ELEMENT: role) are:
- TABLE: table
- THEAD, TFOOT, TBODY: rowgroup
- TR: row
- TD: cell
- TH (with scope "col" OR without scope): columnheader
- TH (with scope "row"): rowheader
- TH (with scope "colgroup"): columngroupheader
- TH (with scope "rowgroup"): rowgroupheader
Note:
The table header cell elements (TH) may not contain the scope "auto" as no ARIA
role can be inferred from this scope.
Usage
import { addAriaToAllTables, addAriaToTable } from "add-aria-to-table";
// Adding ARIA to every html table.
addAriaToAllTables();
// Adding ARIA to a specific html table (may not be null).
const table = document.querySelector("table");
if (table !== null) {
addAriaToTable(table);
}