New rule: flag nested interactive roles
See original GitHub issueNested Interactive Roles
Ensures interactive controls are not nested so they work with keyboards and screen readers
Tags: best-practice, experimental, cat.keyboard
Help text
Ensure interactive controls are not nested.
Selector
a, button, [role="link"], [role="button"]
More info
The code sample below shows a few places where aXe should have flagged nested interactive roles. The developer in this case added a role of link with tabindex, nested a link with role=button and tabindex inside of it, and then put an input with type of image inside. That’s a triple-whammy for nested controls, that we should be able to catch pretty easily since it doesn’t even use click events.
<div role="link" tabindex="40" title="link label">
<a href="/url-went-here" title="link label" role="button" tabindex="12">
Link label
<div class="link-icon">
<input type="image" alt="add to stop throwing error">
</div>
</a>
</div>
Checks
- none: nested-interactives
Issue Analytics
- State:
- Created 6 years ago
- Comments:23 (14 by maintainers)
Top Results From Across the Web
Be Wary of Nesting Roles - Adrian Roselli
The problem is that not all developers understand that throwing a role="button" onto an element turns it into interactive content (much like ...
Read more >Nested interactive controls are not announced by screen ...
Focusable elements with an interactive control ancestor (any element that accepts user input such as button or anchor elements) are not announced by...
Read more >What's New in Axe-core 2021 - Deque Systems
Added 3 new rules (aria-allowed-role, aria-valid-attr, aria-valid-attr- ... Nested interactive controls are not announced by screen readers but.
Read more >nested-interactive - Accessibility Insights
Ensure interactive controls don't have focusable descendants by separating nested interactive components or styling a single element.
Read more >Wcag 4.1.2: Nested Interactive Controls Are Not Announced ...
Connect sidecar content should not use nested interactive controls and any interactive control nested ... New rule: flag nested interactive roles #601.
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
Nesting which results in duplication of announcements in the aural UI is a problem. For sure there are some examples where the result is sort of OK in some browsers with some AT (unknown unless fully tested), but the cost of teasing those out is worth less than accepting that the non-conforming (in HTML) nesting of interactive elements is an issue that should be flagged as an error.
Here is a neat example of a label/interactive control nesting that causes multiple issues; incorrect name calc and misdirected mouse click. This doesn’t appear to be caught by aXE (version 3.3)
Also interactive nesting conformance errors for marcy’s test page. When the DOM is tested (instead of the HTML code) the errors are reduced from 9 to 7.
@gaurav5430 I suggest your replacement example would fall foul of WCAG 2.1 SC 4.1.2 amongst other SC, as they are interactive UI elements that do not convey a
role
, if you add an appropriaterole
to each then you may fall foul of the nesting rules.The authoring requirements for use of ARIA in HTML define what roles can be nested within each role.