-
Notifications
You must be signed in to change notification settings - Fork 776
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rule): Flag div/p/spans/headings in focus order
Flag elements inserted into focus order without semantics that signal interactivity. fixes #632
- Loading branch information
Showing
14 changed files
with
1,254 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
var role = node.getAttribute('role'); | ||
if (role === null) { | ||
return false; | ||
} | ||
var roleType = axe.commons.aria.getRoleType(role); | ||
return roleType === 'widget' || roleType === 'composite'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"id": "has-widget-role", | ||
"evaluate": "has-widget-role.js", | ||
"options": [], | ||
"metadata": { | ||
"impact": "minor", | ||
"messages": { | ||
"pass": "Element has a widget role.", | ||
"fail": "Element does not have a widget role." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* A map from HTML tag names to a boolean which reflects whether it is | ||
* appropriate for scrollable elements found in the focus order. | ||
*/ | ||
const VALID_TAG_NAMES_FOR_SCROLLABLE_REGIONS = { | ||
ARTICLE: true, | ||
ASIDE: true, | ||
NAV: true, | ||
SECTION: true | ||
}; | ||
|
||
/** | ||
* A map from each landmark role to a boolean which reflects whether it is | ||
* appropriate for scrollable elements found in the focus order. | ||
*/ | ||
const VALID_ROLES_FOR_SCROLLABLE_REGIONS = { | ||
banner: false, | ||
complementary: true, | ||
contentinfo: true, | ||
form: true, | ||
main: true, | ||
navigation: true, | ||
region: true, | ||
search: false | ||
}; | ||
|
||
/** | ||
* @param {HTMLElement} node | ||
* @return {Boolean} Whether the element has a tag appropriate for a scrollable | ||
* region. | ||
*/ | ||
function validScrollableTagName(node) { | ||
// Some elements with nonsensical roles will pass this check, but should be | ||
// flagged by other checks. | ||
var tagName = node.tagName.toUpperCase(); | ||
return VALID_TAG_NAMES_FOR_SCROLLABLE_REGIONS[tagName] || false; | ||
} | ||
|
||
/** | ||
* @param {HTMLElement} node | ||
* @return {Boolean} Whether the node has a role appropriate for a scrollable | ||
* region. | ||
*/ | ||
function validScrollableRole(node) { | ||
var role = node.getAttribute('role'); | ||
if (!role) { | ||
return false; | ||
} | ||
return VALID_ROLES_FOR_SCROLLABLE_REGIONS[role.toLowerCase()] || false; | ||
} | ||
|
||
/** | ||
* @param {HTMLElement} node | ||
* @return {Boolean} Whether the element would have valid semantics if it were a | ||
* scrollable region. | ||
*/ | ||
function validScrollableSemantics(node) { | ||
return validScrollableRole(node) || validScrollableTagName(node); | ||
} | ||
|
||
return validScrollableSemantics(node); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"id": "valid-scrollable-semantics", | ||
"evaluate": "valid-scrollable-semantics.js", | ||
"options": [], | ||
"metadata": { | ||
"impact": "minor", | ||
"messages": { | ||
"pass": "Element has valid semantics for an element in the focus order.", | ||
"fail": "Element has invalid semantics for an element in the focus order." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"id": "focus-order-semantics", | ||
"selector": "div, h1, h2, h3, h4, h5, h6, [role=heading], p, span", | ||
"matches": "inserted-into-focus-order-matches.js", | ||
"tags": ["cat.keyboard", "best-practice", "experimental"], | ||
"metadata": { | ||
"description": "Ensures elements in the focus order have an appropriate role", | ||
"help": "Elements in the focus order need a role appropriate for interactive content" | ||
}, | ||
"all": [], | ||
"any": ["has-widget-role", "valid-scrollable-semantics"], | ||
"none": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
return axe.commons.dom.insertedIntoFocusOrder(node); |
Oops, something went wrong.