Programmatic access to the WAI-ARIA 1.2 Roles Model specification with comprehensive role definitions, HTML element mappings, and ARIA property data.
—
Maps ARIA roles to the HTML elements that have those implicit roles. Essential for understanding which HTML elements provide specific ARIA semantics and for tooling that needs to suggest appropriate markup.
Retrieves the HTML elements that have a specific ARIA role implicitly.
/**
* Get HTML elements that have a specific ARIA role implicitly
* @param key - ARIA role name
* @returns Array of HTML element concepts or null if no elements
*/
roleElements.get(key: string): Array<ARIARoleRelationConcept> | null;Usage Examples:
import { roleElements } from "aria-query";
// Get elements that are buttons
const buttonElements = roleElements.get('button');
console.log(buttonElements); // [{ name: "button" }]
// Get elements that are links
const linkElements = roleElements.get('link');
console.log(linkElements); // [{ name: "a" }, { name: "link" }]
// Get elements that are textboxes
const textboxElements = roleElements.get('textbox');
console.log(textboxElements);
// [
// { name: "textarea" },
// { name: "input", attributes: [{ name: "type", value: "text" }] }
// ]
// Get elements that can be headings
const headingElements = roleElements.get('heading');
console.log(headingElements);
// [
// { name: "h1" }, { name: "h2" }, { name: "h3" },
// { name: "h4" }, { name: "h5" }, { name: "h6" }
// ]Determines if an ARIA role has corresponding HTML elements.
/**
* Check if an ARIA role has corresponding HTML elements
* @param key - ARIA role name to check
* @returns True if role has HTML elements, false otherwise
*/
roleElements.has(key: string): boolean;Returns an array of all ARIA role names that have corresponding HTML elements.
/**
* Get array of all ARIA role names that have HTML elements
* @returns Array of role name strings
*/
roleElements.keys(): Array<string>;Returns an array of all HTML element concept arrays.
/**
* Get array of all HTML element concept arrays
* @returns Array of ARIARoleRelationConcept arrays
*/
roleElements.values(): Array<Array<ARIARoleRelationConcept>>;Returns all role-to-element mappings as [role, elements] tuples.
/**
* Get all role-element mappings as [role, elements] tuples
* @returns Array of [string, Array<ARIARoleRelationConcept>] tuples
*/
roleElements.entries(): Array<[string, Array<ARIARoleRelationConcept>]>;Executes a function for each role-to-element mapping.
/**
* Execute function for each role-element mapping
* @param fn - Function to execute for each mapping
* @param thisArg - Optional this context for the function
*/
roleElements.forEach(fn: (elements: Array<ARIARoleRelationConcept>, role: string, entries: Array<[string, Array<ARIARoleRelationConcept>]>) => void, thisArg?: any): void;Usage Examples:
import { roleElements } from "aria-query";
// Find roles that can be represented by multiple element types
const multiElementRoles = [];
roleElements.forEach((elements, role) => {
if (elements.length > 1) {
multiElementRoles.push({ role, elementCount: elements.length });
}
});
// Get all form control roles and their elements
const formRoles = ['textbox', 'button', 'checkbox', 'radio', 'combobox', 'listbox'];
const formElements = {};
formRoles.forEach(role => {
if (roleElements.has(role)) {
formElements[role] = roleElements.get(role);
}
});
// Find elements that can represent list-related roles using entries()
const listRoles = ['list', 'listitem', 'listbox'];
for (const [role, elements] of roleElements.entries()) {
if (listRoles.includes(role)) {
console.log(`${role}:`, elements.map(el => el.name));
}
}
// Same using direct iteration
for (const [role, elements] of roleElements) {
if (listRoles.includes(role)) {
console.log(`${role}:`, elements.map(el => el.name));
}
}// Button role
roleElements.get('button');
// → [{ name: "button" }]
// Textbox role
roleElements.get('textbox');
// → [
// { name: "textarea" },
// { name: "input", attributes: [{ name: "type", value: "text" }] }
// ]
// Checkbox role
roleElements.get('checkbox');
// → [{ name: "input", attributes: [{ name: "type", value: "checkbox" }] }]
// Radio role
roleElements.get('radio');
// → [{ name: "input", attributes: [{ name: "type", value: "radio" }] }]// Link role
roleElements.get('link');
// → [{ name: "a" }, { name: "link" }]
// Navigation role
roleElements.get('navigation');
// → [{ name: "nav" }]// Table role
roleElements.get('table');
// → [{ name: "table" }]
// Cell role
roleElements.get('cell');
// → [{ name: "td" }]
// Heading role
roleElements.get('heading');
// → [{ name: "h1" }, { name: "h2" }, { name: "h3" }, { name: "h4" }, { name: "h5" }, { name: "h6" }]
// List role
roleElements.get('list');
// → [{ name: "ol" }, { name: "ul" }]// Type aliases for collections
type RoleElementRelation = [string, Array<ARIARoleRelationConcept>];
type RoleElementRelations = Array<RoleElementRelation>;
// HTML element concept (same as in element-role mappings)
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'>;
}Install with Tessl CLI
npx tessl i tessl/npm-aria-query