Socket
Socket
Sign inDemoInstall

aria-query

Package Overview
Dependencies
50
Maintainers
4
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    aria-query

Programmatic access to the ARIA specification


Version published
Weekly downloads
27M
decreased by-1.81%
Maintainers
4
Install size
2.15 MB
Created
Weekly downloads
 

Package description

What is aria-query?

The aria-query npm package is a library that provides a set of utilities for querying and interacting with ARIA (Accessible Rich Internet Applications) roles, states, and properties. It is designed to help developers create more accessible web applications by providing an easy way to access and manipulate ARIA attributes.

What are aria-query's main functionalities?

Querying ARIA roles

This feature allows developers to query information about ARIA roles. The code sample demonstrates how to import the 'roles' map from the package and retrieve information about the 'button' role.

import { roles } from 'aria-query';
console.log(roles.get('button'));

Querying ARIA states and properties

This feature enables querying ARIA states and properties. The code sample shows how to import the 'aria' map and get details about the 'aria-hidden' property.

import { aria } from 'aria-query';
console.log(aria.get('aria-hidden'));

Mapping HTML elements to ARIA roles

This feature provides a mapping between HTML elements and their corresponding ARIA roles. The code sample illustrates how to get the ARIA roles associated with the 'button' HTML element.

import { elementRoles } from 'aria-query';
const map = elementRoles.get('button');
console.log(map);

Other packages similar to aria-query

Changelog

Source

5.1.0 / 5.1.1

This minor release introduces iteration support to the primary objects of the module, through the Symbol.iterator property. This reintroduces a native-like Map iteration support that was lost in the v3 update. A forEach method is also introduced in this update. The common interface of all objects exposed by this module is now:

type TAriaQueryMap<E, K, V> = {
  entries: () => E,
  forEach: ((V, K, E) => void) => void,
  get: (key: K) => ?V,
  has: (key: K) => boolean,
  keys: () => Array<K>,
  values: () => Array<V>,
  @@iterator?: () => Iterator<E>,
};

Commits of note

  • 6f3f54b Update dependencies to current minor releases (#437)
  • 855eedc Introduce iteration support to the Maps in the module (#425)
  • 38a2bbc Remove Node 12 as a target for Jest unit testing (#397)
  • 8a0f588 Update out of date packages to latest major versions (#396)
  • 8522117 Ran npm up --dev --save (#395)
  • a21d1ed feat: Add graphics-* roles (#338)

5.1.2

  • 8361a27 Plumb the graphics roles through to rolesMap (#444)

5.1.3

No changes, just trying to get the NPM build to reflect the changes in v5.1.2

5.2.0

[Update] The 5.2.x minor version contains breaking changes and should be skipped.

Commit f7f6120 contains a substantial audit and update of the project to match the ARIA spec. Testing coverage was substantially improved. It really locks down the project's output.

  • e2e3eff docs: update README to WAI-ARIA 1.2 spec (#499)
  • 5ef740f Switch to dequal to remove 45 transitive dependencies (#497)
  • 58da9d5 fix: install command for codesandbox ci (#500)
  • 1160138 test: Publish canaries via CodeSandbox CI (#486)
  • 2d04e29 Add test case to elementRoleMap-test for td element
  • f7f6120 Audited and updated roles source of truth to HTML Accessibility API Mapping 1.0 (#447)

Readme

Source

ARIA Query

CI

Programmatic access to the WAI-ARIA 1.2 Roles Model. This package tracks the stable editor's draft (last update: 21 July 2020).

CDN URL: https://unpkg.com/aria-query

Building the src/etc files

The files under src/etc are generated by the breakUpAriaJSON script.

To change them, edit the file scripts/roles.json then run:

node ./scripts/breakUpAriaJSON.js
git add scripts/roles.json src/etc

It should work with Node version 6.11.2 or later.

Utilities

Interface

These methods are available on each export from the module. The typing here in the documentation is pseudo-typed. Each export will have its own specific types for each method signature.

{|
  entries: () => Array<$Item>,
  get: (key: $Key) => ?$Value,
  has: (key: $Key) => boolean,
  keys: () => Array<$Key>,
  values: () => Array<$Value>,
|};

Roles

import { roles } from 'aria-query';

A map of role names to the role definition. For example:

let alertRole = roles.get('alert');
/**
 * Value of alertRole
 * {
 *   "requiredProps": {},
 *   "props": {
 *     "aria-atomic": "true",
 *     "aria-busy": null,
 *     "aria-controls": null,
 *     "aria-current": null,
 *     "aria-describedby": null,
 *     "aria-details": null,
 *     "aria-disabled": null,
 *     "aria-dropeffect": null,
 *     "aria-errormessage": null,
 *     "aria-expanded": null,
 *     "aria-flowto": null,
 *     "aria-grabbed": null,
 *     "aria-haspopup": null,
 *     "aria-hidden": null,
 *     "aria-invalid": null,
 *     "aria-keyshortcuts": null,
 *     "aria-label": null,
 *     "aria-labelledby": null,
 *     "aria-live": "assertive",
 *     "aria-owns": null,
 *     "aria-relevant": null,
 *     "aria-roledescription": null
 *   },
 *   "abstract": false,
 *   "childrenPresentational": false,
 *   "baseConcepts": [],
 *   "relatedConcepts": [ {
 *     "module": "XForms",
 *     "concept": {
 *       "name": "alert"
 *     }
 *   }],
 *   "superClass": [["roletype", "structure", "section"]]
 * }

Elements to Roles

import { elementRoles } from 'aria-query';

HTML Elements with inherent roles are mapped to those roles. In the case of an element like <input>, the element often requires a type attribute to map to an ARIA role.

[
  [ '{"name": "article"}', [ 'article' ] ],
  [ '{"name": "button"}', [ 'button' ] ],
  [ '{"name": "td"}', [ 'cell', 'gridcell' ] ],
  [ '{"name": "input", "attributes": [ {"name": "type", "value": "checkbox"}] }', [ 'checkbox' ] ],
  [ '{"name": "th"}', [ 'columnheader' ] ],
  [ '{"name": "select"}', [ 'combobox', 'listbox' ] ],
  [ '{"name": "menuitem"}', [ 'command', 'menuitem' ] ],
  [ '{"name": "dd"}', [ 'definition' ] ],
  [ '{"name": "figure"}', [ 'figure' ] ],
  [ '{"name": "form"}', [ 'form' ] ],
  [ '{"name": "table"}', [ 'grid', 'table' ] ],
  [ '{"name": "fieldset"}', [ 'group' ] ],
  [ '{"name": "h1"}', [ 'heading' ] ],
  [ '{"name": "h2"}', [ 'heading' ] ],
  [ '{"name": "h3"}', [ 'heading' ] ],
  [ '{"name": "h4"}', [ 'heading' ] ],
  [ '{"name": "h5"}', [ 'heading' ] ],
  [ '{"name": "h6"}', [ 'heading' ] ],
  [ '{"name": "img"}', [ 'img' ] ],
  [ '{"name": "a"}', [ 'link' ] ],
  [ '{"name": "link"}', [ 'link' ] ],
  [ '{"name": "ol"}', [ 'list' ] ],
  [ '{"name": "ul"}', [ 'list' ] ],
  [ '{"name": "li"}', [ 'listitem' ] ],
  [ '{"name": "nav"}', [ 'navigation' ] ],
  [ '{"name": "option"}', [ 'option' ] ],
  [ '{"name": "input", "attributes": [ {"name": "type", "value": "radio"}] }', [ 'radio' ] ],
  [ '{"name": "frame"}', [ 'region' ] ],
  [ '{"name": "rel"}', [ 'roletype' ] ],
  [ '{"name": "tr"}', [ 'row' ] ],
  [ '{"name": "tbody"}', [ 'rowgroup' ] ],
  [ '{"name": "tfoot"}', [ 'rowgroup' ] ],
  [ '{"name": "thead"}', [ 'rowgroup' ] ],
  [ '{"name": "th", "attributes": [ {"name": "scope", "value": "row"}] }', [ 'rowheader' ] ],
  [ '{"name": "input", "attributes": [ {"name": "type", "value": "search"}] }', [ 'searchbox' ] ],
  [ '{"name": "hr"}', [ 'separator' ] ],
  [ '{"name": "dt"}', [ 'term' ] ],
  [ '{"name": "dfn"}', [ 'term' ] ],
  [ '{"name": "textarea"}', [ 'textbox' ] ],
  [ '{"name": "input", "attributes": [ {"name": "type", "value": "text"}] }', [ 'textbox' ] ],
]

The map of elements to roles is keyed by an HTML concept. An HTML concept corresponds to the baseConcepts and relatedConcepts of an ARIA role. Concepts exist in the context of a module: HTML, XForms, Dublin Core, for example. The concept representation is an object literal with a name property (the element name) and an optional attributes array.

The roles are provided in a Set.

Role to element

import { roleElements } from 'aria-query';

ARIA roles are mapped to the HTML Elements with the same inherent role. Some roles, such as columnheader are only mapped to an HTML element that expresses specific attributes. In the case of <input>, the element often requires a type attribute to map to an ARIA role.

[
  [ 'article', [ {"name": "article"} ] ],
  [ 'button', [ {"name": "button"} ] ],
  [ 'cell', [ {"name": "td"} ] ],
  [ 'checkbox', [ {"name": "input", "attributes": [ {"name": "type", "value": "checkbox"}] } ] ],
  [ 'columnheader', [ {"name": "th"} ] ],
  [ 'combobox', [ {"name": "select"} ] ],
  [ 'command', [ {"name": "menuitem"} ] ],
  [ 'definition', [ {"name": "dd"}', '{"name": "dfn"} ] ],
  [ 'figure', [ {"name": "figure"} ] ],
  [ 'form', [ {"name": "form"} ] ],
  [ 'grid', [ {"name": "table"} ] ],
  [ 'gridcell', [ {"name": "td"} ] ],
  [ 'group', [ {"name": "fieldset"} ] ],
  [ 'heading', [ {"name": "h1"}', '{"name": "h2"}', '{"name": "h3"}', '{"name": "h4"}',  '{"name": "h5"}', '{"name": "h6"} ] ],
  [ 'img', [ {"name": "img"} ] ],
  [ 'link', [ {"name": "a"}', '{"name": "link"} ] ],
  [ 'list', [ {"name": "ol"}', '{"name": "ul"} ] ],
  [ 'listbox', [ {"name": "select"} ] ],
  [ 'listitem', [ {"name": "li"} ] ],
  [ 'menuitem', [ {"name": "menuitem"} ] ],
  [ 'navigation', [ {"name": "nav"} ] ],
  [ 'option', [ {"name": "option"} ] ],
  [ 'radio', [ {"name": "input", "attributes": [ {"name": "type", "value": "radio"}] } ] ],
  [ 'region', [ {"name": "frame"} ] ],
  [ 'roletype', [ {"name": "rel"} ] ],
  [ 'row', [ {"name": "tr"} ] ],
  [ 'rowgroup', [ {"name": "tbody"}', '{"name": "tfoot"}', '{"name": "thead"} ] ],
  [ 'rowheader', [ {"name": "th", "attributes": [ {"name": "scope", "value": "row"}] }, {"name": "th", "attributes": [ {"name": "scope", "value": "rowgroup"}] } ] ],
  [ 'searchbox', [ {"name": "input", "attributes": [ {"name": "type", "value": "search"}] } ] ],
  [ 'separator', [ {"name": "hr"} ] ],
  [ 'table', [ {"name": "table"} ] ],
  [ 'term', [ {"name": "dt"} ] ],
  [ 'textbox', [ {"name": "textarea"}', '{"name": "input", "attributes": [ {"name": "type", "value": "text"}] } ] ],
]

License

Copyright (c) 2021 A11yance

Keywords

FAQs

Last updated on 23 Oct 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc