[A11y] required-context-role
See original GitHub issueRule Requested
The required context role defines the owning container where this role is allowed. If a role has a required context, authors MUST ensure that an element with the role is contained inside (or owned by) an element with the required context role. For example, an element with role="listitem"
is only meaningful when contained inside (or owned by) an element with role="list"
.
Roles to check
Format: role | required context role
- columnheader | row
- gridcell | row
- listitem | group or list
- menuitem | group, menu, or menubar
- menuitemcheckbox | menu or menubar
- menuitemradio | group, menu, or menubar
- option | listbox
- row | grid, rowgroup, or treegrid
- rowgroup | grid
- rowheader | row
- tab | tablist
- treeitem | group or tree
Example(s)
Conformant Code:
<div role="list">
<div role="listitem">Item One</div>
<div role="listitem">Item Two</div>
</div>
Non-conformant code:
<div>
<div role="listitem">Item One</div>
<div role="listitem">Item Two</div>
</div>
Suggested Error Message
(Replace items in brackets with the item that violated the rule)
“You have an element with the role of {{role}} but it is missing the required (immediate) parent element of {{parent-element-options}}. Reference: https://www.w3.org/TR/wai-aria-1.0/roles#{{role}}.”
Reference(s)
- https://www.w3.org/TR/wai-aria-1.0/roles#scope
- https://www.w3.org/TR/wai-aria-1.0/roles#columnheader
- https://www.w3.org/TR/wai-aria-1.0/roles#gridcell
- https://www.w3.org/TR/wai-aria-1.0/roles#listitem
- https://www.w3.org/TR/wai-aria-1.0/roles#menuitem
- https://www.w3.org/TR/wai-aria-1.0/roles#menuitemcheckbox
- https://www.w3.org/TR/wai-aria-1.0/roles#menuitemradio
- https://www.w3.org/TR/wai-aria-1.0/roles#option
- https://www.w3.org/TR/wai-aria-1.0/roles#row
- https://www.w3.org/TR/wai-aria-1.0/roles#rowgroup
- https://www.w3.org/TR/wai-aria-1.0/roles#rowheader
- https://www.w3.org/TR/wai-aria-1.0/roles#tab
- https://www.w3.org/TR/wai-aria-1.0/roles#treeitem
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
ARIA required context role[proposed] | ACT Rule | WAI - W3C
This rule checks that an element with an explicit semantic role exists inside its required context. Applicability. This rule applies to any HTML...
Read more >ARIA required context role - ACT-Rules Community
This rule applies to any HTML or SVG element that is included in the accessibility tree and has a WAI-ARIA 1.1 explicit semantic...
Read more >ARIA: menuitem role - Accessibility - MDN Web Docs
Associated WAI-ARIA roles, states, and properties. menu role. A widget providing a list of choices. Required context role (or menubar ).
Read more >WAI-ARIA: Role=Option - DigitalA11Y
Learn the concepts of Accessible Rich Internet Application [WAI-ARIA] & USING THE WAI-ARIA:Option(role) along with accessible code examples.
Read more >listitem role seems to be missing directory as required context ...
... to write an Accessibility Conformance Testing (ACT) Rule for required context ... Add directory Required Context role to listitem #1062.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sure, I’ll update the issue to include a suggested error message.
@MelSumner - Can you include example template snippets that would be good/bad (doesn’t need to be exhaustive, but I’d like to make sure we are on the same page).