-
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
Changes from 1 commit
0d6604b
0a12490
0ce2ebd
a6fe4be
5687697
6d991a6
eeb6f7e
1be1e8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,17 +4,18 @@ import { isVisible } from '../../commons/dom'; | |||||||||||||||
|
||||||||||||||||
function getLevel(vNode) { | ||||||||||||||||
const role = vNode.attr('role'); | ||||||||||||||||
if (role && role.includes('heading')) { | ||||||||||||||||
const ariaHeadingLevel = vNode.attr('aria-level'); | ||||||||||||||||
const level = parseInt(ariaHeadingLevel, 10); | ||||||||||||||||
|
||||||||||||||||
// 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 (isNaN(level) || level < 1 || level > 6) { | ||||||||||||||||
return 2; | ||||||||||||||||
} | ||||||||||||||||
const headingRole = role && role.includes('heading'); | ||||||||||||||||
const ariaHeadingLevel = vNode.attr('aria-level'); | ||||||||||||||||
const level = parseInt(ariaHeadingLevel, 10); | ||||||||||||||||
|
||||||||||||||||
// 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) { | ||||||||||||||||
return 2; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
if (level) { | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will return the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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
|
||||||||||||||||
return 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 is going to fail on
<h1 role="heading">
. Not sure if that's a new problem, but it's a problem.