axe-core icon indicating copy to clipboard operation
axe-core copied to clipboard

aria-required-children should not permit mixing child roles

Open WilcoFiers opened this issue 2 years ago • 1 comments

Axe-core's aria-required-children rule shouldn't pass the following:

<div role="list">
  <li>Item 1</li>
  <span role="link">Item 2</span>
</div>

WAI-ARIA is a little vague about whether or not you're allowed to do this. There are scenarios, such as for radiogroup where owned elements might not all need to be of the required owned elements type, but for something like lists and trees, that doesn't seem right.

Failing the above example is required for consistency with the ARIA required owned elements ACT rule.

WilcoFiers avatar May 19 '22 10:05 WilcoFiers

We can do this by filtering the ownedRoles array and seeing which ones are not required

const invalidRoles = ownedRoles.filter(role => !required.includes(role));
  if (invalidRoles) {
    this.data({

    })
    return false;
  }

The tricky part is that we should also return the nodes these roles belong to so we can add them to the relatedNodes. The error message should not mention the roles of the elements but instead just focus on there are elements that are not allowed as children (so <div aria-live="polite"></div> can be shown as a related node even though it has no role).

straker avatar Aug 10 '22 15:08 straker

Validated with the latest develop branch code base, the script below is failing arai-required-children rule

<div role="list">
    <li>Item 1</li>
    <span role="link">Item 2</span>
  </div>
image

padmavemulapati avatar Aug 29 '22 14:08 padmavemulapati