| 1 | # ARIA Query
|
|---|
| 2 |
|
|---|
| 3 | 
|
|---|
| 4 |
|
|---|
| 5 | Programmatic access to the [WAI-ARIA 1.2 Roles Model](https://www.w3.org/TR/wai-aria-1.2/#roles).
|
|---|
| 6 | This package tracks the W3C Recommendation (last update: 6 June 2023).
|
|---|
| 7 |
|
|---|
| 8 | CDN URL: <https://unpkg.com/aria-query>
|
|---|
| 9 |
|
|---|
| 10 | ## Building the `src/etc` files
|
|---|
| 11 |
|
|---|
| 12 | The files under `src/etc` are generated by the `breakUpAriaJSON` script.
|
|---|
| 13 |
|
|---|
| 14 | To change them, edit the file `scripts/roles.json` then run:
|
|---|
| 15 |
|
|---|
| 16 | ```bash
|
|---|
| 17 | node ./scripts/breakUpAriaJSON.js
|
|---|
| 18 | git add scripts/roles.json src/etc
|
|---|
| 19 | ```
|
|---|
| 20 |
|
|---|
| 21 | It should work with Node version 6.11.2 or later.
|
|---|
| 22 |
|
|---|
| 23 | ## Utilities
|
|---|
| 24 |
|
|---|
| 25 | ### Interface
|
|---|
| 26 |
|
|---|
| 27 | 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.
|
|---|
| 28 |
|
|---|
| 29 | ```javascript
|
|---|
| 30 | {|
|
|---|
| 31 | entries: () => Array<$Item>,
|
|---|
| 32 | get: (key: $Key) => ?$Value,
|
|---|
| 33 | has: (key: $Key) => boolean,
|
|---|
| 34 | keys: () => Array<$Key>,
|
|---|
| 35 | values: () => Array<$Value>,
|
|---|
| 36 | |};
|
|---|
| 37 | ```
|
|---|
| 38 |
|
|---|
| 39 | ### Roles
|
|---|
| 40 |
|
|---|
| 41 | ```javascript
|
|---|
| 42 | import { roles } from 'aria-query';
|
|---|
| 43 | ```
|
|---|
| 44 |
|
|---|
| 45 | A map of role names to the role definition. For example:
|
|---|
| 46 |
|
|---|
| 47 | ```javascript
|
|---|
| 48 | let alertRole = roles.get('alert');
|
|---|
| 49 | /**
|
|---|
| 50 | * Value of alertRole
|
|---|
| 51 | * {
|
|---|
| 52 | * "requiredProps": {},
|
|---|
| 53 | * "props": {
|
|---|
| 54 | * "aria-atomic": "true",
|
|---|
| 55 | * "aria-busy": null,
|
|---|
| 56 | * "aria-controls": null,
|
|---|
| 57 | * "aria-current": null,
|
|---|
| 58 | * "aria-describedby": null,
|
|---|
| 59 | * "aria-details": null,
|
|---|
| 60 | * "aria-disabled": null,
|
|---|
| 61 | * "aria-dropeffect": null,
|
|---|
| 62 | * "aria-errormessage": null,
|
|---|
| 63 | * "aria-expanded": null,
|
|---|
| 64 | * "aria-flowto": null,
|
|---|
| 65 | * "aria-grabbed": null,
|
|---|
| 66 | * "aria-haspopup": null,
|
|---|
| 67 | * "aria-hidden": null,
|
|---|
| 68 | * "aria-invalid": null,
|
|---|
| 69 | * "aria-keyshortcuts": null,
|
|---|
| 70 | * "aria-label": null,
|
|---|
| 71 | * "aria-labelledby": null,
|
|---|
| 72 | * "aria-live": "assertive",
|
|---|
| 73 | * "aria-owns": null,
|
|---|
| 74 | * "aria-relevant": null,
|
|---|
| 75 | * "aria-roledescription": null
|
|---|
| 76 | * },
|
|---|
| 77 | * "abstract": false,
|
|---|
| 78 | * "childrenPresentational": false,
|
|---|
| 79 | * "baseConcepts": [],
|
|---|
| 80 | * "relatedConcepts": [ {
|
|---|
| 81 | * "module": "XForms",
|
|---|
| 82 | * "concept": {
|
|---|
| 83 | * "name": "alert"
|
|---|
| 84 | * }
|
|---|
| 85 | * }],
|
|---|
| 86 | * "superClass": [["roletype", "structure", "section"]]
|
|---|
| 87 | * }
|
|---|
| 88 | ```
|
|---|
| 89 |
|
|---|
| 90 | ### Elements to Roles
|
|---|
| 91 |
|
|---|
| 92 | ```javascript
|
|---|
| 93 | import { elementRoles } from 'aria-query';
|
|---|
| 94 | ```
|
|---|
| 95 |
|
|---|
| 96 | 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.
|
|---|
| 97 |
|
|---|
| 98 | ```javascript
|
|---|
| 99 | [
|
|---|
| 100 | [ '{"name": "article"}', [ 'article' ] ],
|
|---|
| 101 | [ '{"name": "button"}', [ 'button' ] ],
|
|---|
| 102 | [ '{"name": "td"}', [ 'cell', 'gridcell' ] ],
|
|---|
| 103 | [ '{"name": "input", "attributes": [ {"name": "type", "value": "checkbox"}] }', [ 'checkbox' ] ],
|
|---|
| 104 | [ '{"name": "th"}', [ 'columnheader' ] ],
|
|---|
| 105 | [ '{"name": "select"}', [ 'combobox', 'listbox' ] ],
|
|---|
| 106 | [ '{"name": "menuitem"}', [ 'command', 'menuitem' ] ],
|
|---|
| 107 | [ '{"name": "dd"}', [ 'definition' ] ],
|
|---|
| 108 | [ '{"name": "figure"}', [ 'figure' ] ],
|
|---|
| 109 | [ '{"name": "form"}', [ 'form' ] ],
|
|---|
| 110 | [ '{"name": "table"}', [ 'grid', 'table' ] ],
|
|---|
| 111 | [ '{"name": "fieldset"}', [ 'group' ] ],
|
|---|
| 112 | [ '{"name": "h1"}', [ 'heading' ] ],
|
|---|
| 113 | [ '{"name": "h2"}', [ 'heading' ] ],
|
|---|
| 114 | [ '{"name": "h3"}', [ 'heading' ] ],
|
|---|
| 115 | [ '{"name": "h4"}', [ 'heading' ] ],
|
|---|
| 116 | [ '{"name": "h5"}', [ 'heading' ] ],
|
|---|
| 117 | [ '{"name": "h6"}', [ 'heading' ] ],
|
|---|
| 118 | [ '{"name": "img"}', [ 'img' ] ],
|
|---|
| 119 | [ '{"name": "a"}', [ 'link' ] ],
|
|---|
| 120 | [ '{"name": "link"}', [ 'link' ] ],
|
|---|
| 121 | [ '{"name": "ol"}', [ 'list' ] ],
|
|---|
| 122 | [ '{"name": "ul"}', [ 'list' ] ],
|
|---|
| 123 | [ '{"name": "li"}', [ 'listitem' ] ],
|
|---|
| 124 | [ '{"name": "nav"}', [ 'navigation' ] ],
|
|---|
| 125 | [ '{"name": "option"}', [ 'option' ] ],
|
|---|
| 126 | [ '{"name": "input", "attributes": [ {"name": "type", "value": "radio"}] }', [ 'radio' ] ],
|
|---|
| 127 | [ '{"name": "frame"}', [ 'region' ] ],
|
|---|
| 128 | [ '{"name": "rel"}', [ 'roletype' ] ],
|
|---|
| 129 | [ '{"name": "tr"}', [ 'row' ] ],
|
|---|
| 130 | [ '{"name": "tbody"}', [ 'rowgroup' ] ],
|
|---|
| 131 | [ '{"name": "tfoot"}', [ 'rowgroup' ] ],
|
|---|
| 132 | [ '{"name": "thead"}', [ 'rowgroup' ] ],
|
|---|
| 133 | [ '{"name": "th", "attributes": [ {"name": "scope", "value": "row"}] }', [ 'rowheader' ] ],
|
|---|
| 134 | [ '{"name": "input", "attributes": [ {"name": "type", "value": "search"}] }', [ 'searchbox' ] ],
|
|---|
| 135 | [ '{"name": "hr"}', [ 'separator' ] ],
|
|---|
| 136 | [ '{"name": "dt"}', [ 'term' ] ],
|
|---|
| 137 | [ '{"name": "dfn"}', [ 'term' ] ],
|
|---|
| 138 | [ '{"name": "textarea"}', [ 'textbox' ] ],
|
|---|
| 139 | [ '{"name": "input", "attributes": [ {"name": "type", "value": "text"}] }', [ 'textbox' ] ],
|
|---|
| 140 | ]
|
|---|
| 141 | ```
|
|---|
| 142 |
|
|---|
| 143 | 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.
|
|---|
| 144 |
|
|---|
| 145 | The roles are provided in a [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set).
|
|---|
| 146 |
|
|---|
| 147 | ### Role to element
|
|---|
| 148 |
|
|---|
| 149 | ```javascript
|
|---|
| 150 | import { roleElements } from 'aria-query';
|
|---|
| 151 | ```
|
|---|
| 152 |
|
|---|
| 153 | 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.
|
|---|
| 154 |
|
|---|
| 155 | ```javascript
|
|---|
| 156 | [
|
|---|
| 157 | [ 'article', [ {"name": "article"} ] ],
|
|---|
| 158 | [ 'button', [ {"name": "button"} ] ],
|
|---|
| 159 | [ 'cell', [ {"name": "td"} ] ],
|
|---|
| 160 | [ 'checkbox', [ {"name": "input", "attributes": [ {"name": "type", "value": "checkbox"}] } ] ],
|
|---|
| 161 | [ 'columnheader', [ {"name": "th"} ] ],
|
|---|
| 162 | [ 'combobox', [ {"name": "select"} ] ],
|
|---|
| 163 | [ 'command', [ {"name": "menuitem"} ] ],
|
|---|
| 164 | [ 'definition', [ {"name": "dd"}', '{"name": "dfn"} ] ],
|
|---|
| 165 | [ 'figure', [ {"name": "figure"} ] ],
|
|---|
| 166 | [ 'form', [ {"name": "form"} ] ],
|
|---|
| 167 | [ 'grid', [ {"name": "table"} ] ],
|
|---|
| 168 | [ 'gridcell', [ {"name": "td"} ] ],
|
|---|
| 169 | [ 'group', [ {"name": "fieldset"} ] ],
|
|---|
| 170 | [ 'heading', [ {"name": "h1"}', '{"name": "h2"}', '{"name": "h3"}', '{"name": "h4"}', '{"name": "h5"}', '{"name": "h6"} ] ],
|
|---|
| 171 | [ 'img', [ {"name": "img"} ] ],
|
|---|
| 172 | [ 'link', [ {"name": "a"}', '{"name": "link"} ] ],
|
|---|
| 173 | [ 'list', [ {"name": "ol"}', '{"name": "ul"} ] ],
|
|---|
| 174 | [ 'listbox', [ {"name": "select"} ] ],
|
|---|
| 175 | [ 'listitem', [ {"name": "li"} ] ],
|
|---|
| 176 | [ 'menuitem', [ {"name": "menuitem"} ] ],
|
|---|
| 177 | [ 'navigation', [ {"name": "nav"} ] ],
|
|---|
| 178 | [ 'option', [ {"name": "option"} ] ],
|
|---|
| 179 | [ 'radio', [ {"name": "input", "attributes": [ {"name": "type", "value": "radio"}] } ] ],
|
|---|
| 180 | [ 'region', [ {"name": "frame"} ] ],
|
|---|
| 181 | [ 'roletype', [ {"name": "rel"} ] ],
|
|---|
| 182 | [ 'row', [ {"name": "tr"} ] ],
|
|---|
| 183 | [ 'rowgroup', [ {"name": "tbody"}', '{"name": "tfoot"}', '{"name": "thead"} ] ],
|
|---|
| 184 | [ 'rowheader', [ {"name": "th", "attributes": [ {"name": "scope", "value": "row"}] }, {"name": "th", "attributes": [ {"name": "scope", "value": "rowgroup"}] } ] ],
|
|---|
| 185 | [ 'searchbox', [ {"name": "input", "attributes": [ {"name": "type", "value": "search"}] } ] ],
|
|---|
| 186 | [ 'separator', [ {"name": "hr"} ] ],
|
|---|
| 187 | [ 'table', [ {"name": "table"} ] ],
|
|---|
| 188 | [ 'term', [ {"name": "dt"} ] ],
|
|---|
| 189 | [ 'textbox', [ {"name": "textarea"}', '{"name": "input", "attributes": [ {"name": "type", "value": "text"}] } ] ],
|
|---|
| 190 | ]
|
|---|
| 191 | ```
|
|---|
| 192 |
|
|---|
| 193 | ## License
|
|---|
| 194 |
|
|---|
| 195 | Copyright (c) 2021 A11yance
|
|---|