Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[A11y] required-context-role #626

Closed
MelSumner opened this issue Jan 23, 2019 · 9 comments · Fixed by #636
Closed

[A11y] required-context-role #626

MelSumner opened this issue Jan 23, 2019 · 9 comments · Fixed by #636
Labels
a11y accessibility-related enhancement

Comments

@MelSumner
Copy link
Contributor

MelSumner commented Jan 23, 2019

Rule 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)

@rwjblue
Copy link
Member

rwjblue commented Jan 23, 2019

@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).

@lifeart
Copy link
Collaborator

lifeart commented Jan 24, 2019

@rwjblue any common/easy way to check parents without stack in hbs AST?

@lifeart
Copy link
Collaborator

lifeart commented Jan 24, 2019

@MelSumner, is this case valid?

<div role="list">
  <div>
      <div role="listitem">Item One</div>
      <div role="listitem">Item Two</div>
  </div>
</div>

when we have few nodes between roles

@MelSumner
Copy link
Contributor Author

@lifeart no, that's not valid.

@lifeart
Copy link
Collaborator

lifeart commented Jan 24, 2019

@MelSumner can you provide error message for this rule?

@lifeart
Copy link
Collaborator

lifeart commented Jan 24, 2019

I can take it

@MelSumner
Copy link
Contributor Author

@MelSumner can you provide error message for this rule?

Sure, I'll update the issue to include a suggested error message.

lifeart added a commit to lifeart/ember-template-lint that referenced this issue Jan 24, 2019
@lifeart
Copy link
Collaborator

lifeart commented Jan 24, 2019

Done

lifeart added a commit to lifeart/ember-template-lint that referenced this issue Aug 10, 2020
@MelSumner MelSumner added the a11y accessibility-related label Apr 15, 2021
lifeart added a commit to lifeart/ember-template-lint that referenced this issue Oct 4, 2021
@bmish bmish closed this as completed in #636 Oct 4, 2021
@roomman
Copy link

roomman commented May 25, 2022

@lifeart no, that's not valid.

@MelSumner, the mdn docs suggest it's okay to include a presentation element between the parent (eg 'menu') and child roles (eg 'menuitem"): https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/menuitem_role

Are those docs incorrect or does this rule need to be updated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a11y accessibility-related enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants