-
Notifications
You must be signed in to change notification settings - Fork 791
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
fix(heading-order): use aria-level on headings in addition to role=header elements #3028
Conversation
// default aria-level for a heading is 2 if it is | ||
// not set or set to an incorrect value | ||
// @see https://www.w3.org/TR/wai-aria-1.1/#heading | ||
if ((headingRole && isNaN(level)) || level < 1 || level > 6) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to fail on <h1 role="heading">
. Not sure if that's a new problem, but it's a problem.
|
||
if (level) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will return the aria-level
for non-header elements like <iframe aria-level="2"></iframe>
, when we actually need the iframe to be level=-1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rule doesn't run on iframes, as far as I can tell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rule doesn't, but we use a selector inside the evaluate to look for iframes and assign them a level of -1 so in the after we can reconstruct heading order correctly for all iframes on the page.
axe-core/lib/checks/navigation/heading-order-evaluate.js
Lines 40 to 46 in 0d6604b
const selector = 'h1, h2, h3, h4, h5, h6, [role=heading], iframe, frame'; | |
// TODO: es-modules_tree | |
const vNodes = querySelectorAllFilter(axe._tree[0], selector, vNode => | |
isVisible(vNode.actualNode, true) | |
); | |
headingOrder = vNodes.map(vNode => { |
Co-authored-by: Wilco Fiers <[email protected]>
Co-authored-by: Steven Lambert <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is the last thing. Everything else looks good. Good work.
Co-authored-by: Steven Lambert <[email protected]>
* @see https://www.w3.org/TR/wai-aria-1.1/#heading | ||
* @see https://codepen.io/straker/pen/jOBjNNe | ||
*/ | ||
if (isNaN(ariaLevel) || ariaLevel < 1 || ariaLevel > 6) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright. Wilco and I talked and we came to the conclusion that we want to change how we're handling positive values. Since aria-level
> 6 is handled differently by different screen readers, we're going to flag it as part of a new check for aria-valid-attr-value and call out its lack of support.
But for heading-order we're just going to accept what the user gave us so there isn't two different failures caused by the same problem.
if (isNaN(ariaLevel) || ariaLevel < 1 || ariaLevel > 6) { | |
if (isNaN(ariaLevel) || ariaLevel < 1) { |
Allow aria-level on hn elements to override the semantic level of the element.
Closes issue: #2971