Programmatic access to the WAI-ARIA 1.2 Roles Model specification with comprehensive role definitions, HTML element mappings, and ARIA property data.
—
Maps HTML elements (with optional attributes) to their implicit ARIA roles. Essential for determining the semantic meaning of HTML markup and understanding accessibility implications.
Retrieves the implicit ARIA roles for a specific HTML element concept.
/**
* Get implicit ARIA roles for an HTML element concept
* @param key - HTML element concept with name and optional attributes
* @returns Array of role names or null if no implicit roles
*/
elementRoles.get(key: ARIARoleRelationConcept): Array<string> | null;Usage Examples:
import { elementRoles } from "aria-query";
// Simple element - button
const buttonElement = { name: "button" };
const buttonRoles = elementRoles.get(buttonElement);
console.log(buttonRoles); // ['button']
// Element with attributes - input type="checkbox"
const checkboxInput = {
name: "input",
attributes: [{ name: "type", value: "checkbox" }]
};
const checkboxRoles = elementRoles.get(checkboxInput);
console.log(checkboxRoles); // ['checkbox']
// Element with multiple possible roles - select
const selectElement = { name: "select" };
const selectRoles = elementRoles.get(selectElement);
console.log(selectRoles); // ['combobox', 'listbox']
// Element with scope attribute - th with row scope
const rowHeaderTh = {
name: "th",
attributes: [{ name: "scope", value: "row" }]
};
const rowHeaderRoles = elementRoles.get(rowHeaderTh);
console.log(rowHeaderRoles); // ['rowheader']Determines if an HTML element concept has implicit ARIA roles.
/**
* Check if an HTML element concept has implicit ARIA roles
* @param key - HTML element concept to check
* @returns True if element has implicit roles, false otherwise
*/
elementRoles.has(key: ARIARoleRelationConcept): boolean;Returns an array of all HTML element concepts that have implicit roles.
/**
* Get array of all HTML element concepts with implicit roles
* @returns Array of ARIARoleRelationConcept objects
*/
elementRoles.keys(): Array<ARIARoleRelationConcept>;Returns an array of all role sets (arrays of role names).
/**
* Get array of all role sets for elements
* @returns Array of role name arrays
*/
elementRoles.values(): Array<Array<string>>;Returns all element-to-role mappings as [element, roles] tuples.
/**
* Get all element-role mappings as [element, roles] tuples
* @returns Array of [ARIARoleRelationConcept, Array<string>] tuples
*/
elementRoles.entries(): Array<[ARIARoleRelationConcept, Array<string>]>;Executes a function for each element-to-role mapping.
/**
* Execute function for each element-role mapping
* @param fn - Function to execute for each mapping
* @param thisArg - Optional this context for the function
*/
elementRoles.forEach(fn: (roles: Array<string>, element: ARIARoleRelationConcept, entries: Array<[ARIARoleRelationConcept, Array<string>]>) => void, thisArg?: any): void;Usage Examples:
import { elementRoles } from "aria-query";
// Find all elements that can be buttons
const buttonElements = [];
elementRoles.forEach((roles, element) => {
if (roles.includes('button')) {
buttonElements.push(element);
}
});
// Find elements with multiple role possibilities using entries()
const multiRoleElements = [];
for (const [element, roles] of elementRoles.entries()) {
if (roles.length > 1) {
multiRoleElements.push({ element: element.name, roles });
}
}
// Same using direct iteration
const multiRoleElements2 = [];
for (const [element, roles] of elementRoles) {
if (roles.length > 1) {
multiRoleElements2.push({ element: element.name, roles });
}
}
// Check if a specific input type has roles
const textInput = {
name: "input",
attributes: [{ name: "type", value: "text" }]
};
if (elementRoles.has(textInput)) {
console.log('Text input has implicit roles:', elementRoles.get(textInput));
}// Input elements with type attributes
const textInput = { name: "input", attributes: [{ name: "type", value: "text" }] };
// → ['textbox']
const radioInput = { name: "input", attributes: [{ name: "type", value: "radio" }] };
// → ['radio']
const checkboxInput = { name: "input", attributes: [{ name: "type", value: "checkbox" }] };
// → ['checkbox']
// Select elements
const selectElement = { name: "select" };
// → ['combobox', 'listbox']
// Textarea
const textareaElement = { name: "textarea" };
// → ['textbox']// Headings
const h1Element = { name: "h1" };
// → ['heading']
// Lists
const ulElement = { name: "ul" };
// → ['list']
const liElement = { name: "li" };
// → ['listitem']
// Tables
const tableElement = { name: "table" };
// → ['grid', 'table']
const tdElement = { name: "td" };
// → ['cell', 'gridcell']// HTML element concept with optional attributes and constraints
interface ARIARoleRelationConcept {
/** HTML element name */
name: string;
/** Optional attributes that affect the role mapping */
attributes?: Array<ARIARoleRelationConceptAttribute>;
/** Contextual constraints for the mapping */
constraints?: Array<string>;
}
// Attribute specification for element concepts
interface ARIARoleRelationConceptAttribute {
/** Attribute name */
name: string;
/** Attribute value (optional for boolean attributes) */
value?: string | number;
/** Constraints on the attribute */
constraints?: Array<'undefined' | 'set' | '>1'>;
}
// Type aliases for collections
type ElementARIARoleRelationTuple = [ARIARoleRelationConcept, Array<string>];
type ElementARIARoleRelations = Array<ElementARIARoleRelationTuple>;Install with Tessl CLI
npx tessl i tessl/npm-aria-query