dequelabs / axe-core

Accessibility engine for automated Web UI testing
https://www.deque.com/axe/
Mozilla Public License 2.0
5.75k stars 746 forks source link

role="tab" not working as expected for `<input type="radio"/>` (ARIA role tab is not allowed for given element) #4431

Closed nmerget closed 2 months ago

nmerget commented 2 months ago

Product

axe-core

Product Version

4.9.0

Latest Version

Issue Description

Expectation

The playwright tests shouldn't fail.

Actual

The playwright test fails with:

   "failureSummary": "Fix any of the following:
   ARIA role tab is not allowed for given element",
         "html": "<input role=\"tab\" type=\"radio\" aria-selected=\"true\" id=\"983a0cfc-19a3-4187-ae7a-e0a4b10b3cd0-tab-0\" aria-controls=\"983a0cfc-19a3-4187-ae7a-e0a4b10b3cd0-tab-panel-0\" name=\"983a0cfc-19a3-4187-ae7a-e0a4b10b3cd0\">",

How to Reproduce

Minimal example:

https://jsbin.com/cahifuvezi/edit?html,css,output

Additional context

Based on https://w3c.github.io/aria/#tab the role=tab should be accessibility children of tablist:

Authors MUST ensure elements with role tab are accessibility children of an element with the role tablist.

Based on my example I get this in Chrome: image

Which should be fine πŸΆβ˜•πŸ”₯

Maybe axe only looks at the "real" DOM-Nodes to check for the roles? Also, I'm unsure if tab has to be a direct child of tablist. The issue comes from wrapping the role=tab in <li><label><input role=tab>. To avoid the error I could add the role=tab to <li> but I would get another error because role=presentation can't have a focusable child (which is the <input type="radio"/>).

I tried nearly every combination to get a "correct" accessibility tree, so I think there should be an issue with axe resolving the nodes?

-> Why didn't we use a tab with button, because the <input type="radio"/> provides keyboard functions out of the box. I like this approach and I don't want to add additional JS to solve this.

straker commented 2 months ago

Thanks for the issue. What ARIA roles and attributes are allowed on which HTML elements is dictated by the ARIA in HTML spec. Specifically for input[type="radio'] only the menuitemradio role is allowed, which is why axe is saying the tab role is not allowed on the element.