Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

README.md 6.3 KiB

3 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. [![Build Status](https://travis-ci.org/A11yance/aria-query.svg?branch=master)](https://travis-ci.org/A11yance/aria-query)
  2. CDN URL: https://npm-cdn.com/pkg/aria-query/
  3. # ARIA Query
  4. Programmatic access to the [WAI-ARIA 1.1 Roles Model](https://www.w3.org/TR/wai-aria-1.1/#roles).
  5. ## Utilities
  6. ### Roles
  7. ```
  8. import { roles } from 'aria-query';
  9. ```
  10. A [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) of
  11. role names to the role definition. For example:
  12. ```
  13. let alertRole = roles.get('alert');
  14. /**
  15. * Value of alertRole
  16. * {
  17. * "requiredProps": [],
  18. * "props": [
  19. * "aria-expanded",
  20. * "aria-atomic",
  21. * "aria-busy",
  22. * "aria-controls",
  23. * "aria-describedby",
  24. * "aria-disabled",
  25. * "aria-dropeffect",
  26. * "aria-flowto",
  27. * "aria-grabbed",
  28. * "aria-haspopup",
  29. * "aria-hidden",
  30. * "aria-invalid",
  31. * "aria-label",
  32. * "aria-labelledby",
  33. * "aria-live",
  34. * "aria-owns",
  35. * "aria-relevant"
  36. * ],
  37. * "abstract": false,
  38. * "interactive": false,
  39. * "childrenPresentational": false,
  40. * "baseConcepts": [],
  41. * "relatedConcepts": [ {
  42. * "module": "XForms",
  43. * "concept": {
  44. * "name": "alert"
  45. * }
  46. * }]
  47. * }
  48. ```
  49. ### Elements to Roles
  50. ```
  51. import { elementRoles } from 'aria-query';
  52. ```
  53. 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.
  54. ```
  55. Map {
  56. '{"name": "article"}' => Set { 'article' },
  57. '{"name": "button"}' => Set { 'button' },
  58. '{"name": "td"}' => Set { 'cell', 'gridcell' },
  59. '{"name": "input", "attributes": [ {"name": "type", "value": "checkbox"}] }' => Set { 'checkbox' },
  60. '{"name": "th"}' => Set { 'columnheader' },
  61. '{"name": "select"}' => Set { 'combobox', 'listbox' },
  62. '{"name": "menuitem"}' => Set { 'command', 'menuitem' },
  63. '{"name": "dd"}' => Set { 'definition' },
  64. '{"name": "dfn"}' => Set { 'definition' },
  65. '{"name": "figure"}' => Set { 'figure' },
  66. '{"name": "form"}' => Set { 'form' },
  67. '{"name": "table"}' => Set { 'grid', 'table' },
  68. '{"name": "fieldset"}' => Set { 'group' },
  69. '{"name": "h1"}' => Set { 'heading' },
  70. '{"name": "h2"}' => Set { 'heading' },
  71. '{"name": "h3"}' => Set { 'heading' },
  72. '{"name": "h4"}' => Set { 'heading' },
  73. '{"name": "h5"}' => Set { 'heading' },
  74. '{"name": "h6"}' => Set { 'heading' },
  75. '{"name": "img"}' => Set { 'img' },
  76. '{"name": "a"}' => Set { 'link' },
  77. '{"name": "link"}' => Set { 'link' },
  78. '{"name": "ol"}' => Set { 'list' },
  79. '{"name": "ul"}' => Set { 'list' },
  80. '{"name": "li"}' => Set { 'listitem' },
  81. '{"name": "nav"}' => Set { 'navigation' },
  82. '{"name": "option"}' => Set { 'option' },
  83. '{"name": "input", "attributes": [ {"name": "type", "value": "radio"}] }' => Set { 'radio' },
  84. '{"name": "frame"}' => Set { 'region' },
  85. '{"name": "rel"}' => Set { 'roletype' },
  86. '{"name": "tr"}' => Set { 'row' },
  87. '{"name": "tbody"}' => Set { 'rowgroup' },
  88. '{"name": "tfoot"}' => Set { 'rowgroup' },
  89. '{"name": "thead"}' => Set { 'rowgroup' },
  90. '{"name": "th", "attributes": [ {"name": "scope", "value": "row"}] }' => Set { 'rowheader' },
  91. '{"name": "input", "attributes": [ {"name": "type", "value": "search"}] }' => Set { 'searchbox' },
  92. '{"name": "hr"}' => Set { 'separator' },
  93. '{"name": "dt"}' => Set { 'term' },
  94. '{"name": "textarea"}' => Set { 'textbox' },
  95. '{"name": "input", "attributes": [ {"name": "type", "value": "text"}] }' => Set { 'textbox' }
  96. }
  97. ```
  98. 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.
  99. The roles are provided in a [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set).
  100. ### Role to element
  101. ```
  102. import { roleElements } from 'aria-query';
  103. ```
  104. ARIA roles are mapped to the HTML Elements with the same inherent role. Some roles, such as `columnheader` are only mapped to an HMTL element that expresses specific attributes. In the case of `<input>`, the element often requires a `type` attribute to map to an ARIA role.
  105. ```
  106. Map {
  107. 'article' => Set { '{"name": "article"}' },
  108. 'button' => Set { '{"name": "button"}' },
  109. 'cell' => Set { '{"name": "td"}' },
  110. 'checkbox' => Set { '{"name": "input", "attributes": [ {"name": "type", "value": "checkbox"}] }' },
  111. 'columnheader' => Set { '{"name": "th"}' },
  112. 'combobox' => Set { '{"name": "select"}' },
  113. 'command' => Set { '{"name": "menuitem"}' },
  114. 'definition' => Set { '{"name": "dd"}', '{"name": "dfn"}' },
  115. 'figure' => Set { '{"name": "figure"}' },
  116. 'form' => Set { '{"name": "form"}' },
  117. 'grid' => Set { '{"name": "table"}' },
  118. 'gridcell' => Set { '{"name": "td"}' },
  119. 'group' => Set { '{"name": "fieldset"}' },
  120. 'heading' => Set { '{"name": "h1"}', '{"name": "h2"}', '{"name": "h3"}', '{"name": "h4"}', '{"name": "h5"}', '{"name": "h6"}' },
  121. 'img' => Set { '{"name": "img"}' },
  122. 'link' => Set { '{"name": "a"}', '{"name": "link"}' },
  123. 'list' => Set { '{"name": "ol"}', '{"name": "ul"}' },
  124. 'listbox' => Set { '{"name": "select"}' },
  125. 'listitem' => Set { '{"name": "li"}' },
  126. 'menuitem' => Set { '{"name": "menuitem"}' },
  127. 'navigation' => Set { '{"name": "nav"}' },
  128. 'option' => Set { '{"name": "option"}' },
  129. 'radio' => Set { '{"name": "input", "attributes": [ {"name": "type", "value": "radio"}] }' },
  130. 'region' => Set { '{"name": "frame"}' },
  131. 'roletype' => Set { '{"name": "rel"}' },
  132. 'row' => Set { '{"name": "tr"}' },
  133. 'rowgroup' => Set { '{"name": "tbody"}', '{"name": "tfoot"}', '{"name": "thead"}' },
  134. 'rowheader' => Set { '{"name": "th", "attributes": [ {"name": "scope", "value": "row"}] }' },
  135. 'searchbox' => Set { '{"name": "input", "attributes": [ {"name": "type", "value": "search"}] }' },
  136. 'separator' => Set { '{"name": "hr"}' },
  137. 'table' => Set { '{"name": "table"}' },
  138. 'term' => Set { '{"name": "dt"}' },
  139. 'textbox' => Set { '{"name": "textarea"}', '{"name": "input", "attributes": [ {"name": "type", "value": "text"}] }' }
  140. }
  141. ```
  142. The HTML concept values are provided in a [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set).