CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-aria-query

Programmatic access to the WAI-ARIA 1.2 Roles Model specification with comprehensive role definitions, HTML element mappings, and ARIA property data.

Pending
Overview
Eval results
Files

role-definitions.mddocs/

ARIA Role Definitions

Complete ARIA role specifications including properties, inheritance chains, and concept mappings from the WAI-ARIA 1.2 specification.

Capabilities

Get Role Definition

Retrieves the complete definition for a specific ARIA role.

/**
 * Get complete definition for an ARIA role
 * @param key - ARIA role name
 * @returns Role definition object or null if not found
 */
roles.get(key: string): ARIARoleDefinition | null;

Usage Examples:

import { roles } from "aria-query";

// Get alert role definition
const alertRole = roles.get('alert');
console.log(alertRole.abstract); // false
console.log(alertRole.props['aria-live']); // "assertive"
console.log(alertRole.superClass); // [["roletype", "structure", "section"]]

// Get button role definition  
const buttonRole = roles.get('button');
console.log(buttonRole.requiredProps); // {}
console.log(buttonRole.nameFrom); // ["author", "contents"]

// Check for abstract role
const commandRole = roles.get('command');
console.log(commandRole.abstract); // true

Check Role Existence

Determines if a role exists in the specification.

/**
 * Check if an ARIA role exists in the specification
 * @param key - ARIA role name to check
 * @returns True if role exists, false otherwise
 */
roles.has(key: string): boolean;

Get All Role Names

Returns an array of all available ARIA role names.

/**
 * Get array of all ARIA role names
 * @returns Array of role name strings
 */
roles.keys(): Array<string>;

Get All Role Definitions

Returns an array of all role definition objects.

/**
 * Get array of all role definition objects
 * @returns Array of ARIARoleDefinition objects
 */
roles.values(): Array<ARIARoleDefinition>;

Get All Role Entries

Returns all roles as an array of [name, definition] tuples.

/**
 * Get all roles as [name, definition] tuples
 * @returns Array of [string, ARIARoleDefinition] tuples
 */
roles.entries(): Array<[string, ARIARoleDefinition]>;

Iterate Over Roles

Executes a function for each role definition.

/**
 * Execute function for each role definition
 * @param fn - Function to execute for each role
 * @param thisArg - Optional this context for the function
 */
roles.forEach(fn: (definition: ARIARoleDefinition, name: string, entries: Array<[string, ARIARoleDefinition]>) => void, thisArg?: any): void;

Usage Examples:

import { roles } from "aria-query";

// Find all roles that require accessible names
const nameRequiredRoles = [];
roles.forEach((definition, name) => {
  if (definition.accessibleNameRequired) {
    nameRequiredRoles.push(name);
  }
});

// Find all abstract roles
const abstractRoles = roles.keys().filter(name => roles.get(name).abstract);

// Get roles with live region properties using entries()
const liveRegionRoles = [];
for (const [name, definition] of roles.entries()) {
  if (definition.props['aria-live']) {
    liveRegionRoles.push(name);
  }
}

// Direct iteration using for...of (equivalent to above)
const liveRegionRoles2 = [];
for (const [name, definition] of roles) {
  if (definition.props['aria-live']) {
    liveRegionRoles2.push(name);
  }
}

Types

// Complete ARIA role definition structure
interface ARIARoleDefinition {
  /** Whether this is an abstract role that cannot be used in HTML */
  abstract: boolean;
  /** Whether an accessible name is required for this role */
  accessibleNameRequired: boolean;
  /** Base concepts that inform behavior mappings */
  baseConcepts: Array<ARIARoleRelation>;
  /** Whether child elements are presentational (flattened to text) */
  childrenPresentational: boolean;
  /** Sources from which accessible names can be derived */
  nameFrom?: Array<ARIANameFromSources>;
  /** ARIA properties and states disallowed on this role */
  prohibitedProps: Array<string>;
  /** ARIA properties and states allowed on this role with default values */
  props: ARIAPropertyMap;
  /** Related concepts in other specifications */
  relatedConcepts: Array<ARIARoleRelation>;
  /** Context roles that may be required */
  requireContextRole?: Array<string>;
  /** Context roles that are required */
  requiredContextRole?: Array<string>;
  /** Required owned elements patterns */
  requiredOwnedElements?: Array<Array<string>>;
  /** ARIA properties and states required on this role */
  requiredProps: ARIAPropertyMap;
  /** Inheritance chains - array of super class stacks */
  superClass: Array<Array<string>>;
}

// Role relation to concepts in other specifications
interface ARIARoleRelation {
  /** Specification module (e.g., "HTML", "XForms") */
  module?: string;
  /** The concept in the related specification */
  concept?: ARIARoleRelationConcept;
}

// Name sources for accessible names
type ARIANameFromSources = 'author' | 'contents' | 'prohibited';

// Property map with optional values
type ARIAPropertyMap = {
  [propertyName: string]: any;
};

Install with Tessl CLI

npx tessl i tessl/npm-aria-query

docs

aria-properties.md

dom-elements.md

element-role-mappings.md

index.md

role-definitions.md

role-element-mappings.md

tile.json