Skip to content

Commit e75324b

Browse files
committed
fix(has-no-more-than-one-main): Rename check to page-no-duplicate for better reuse
1 parent ced7f2f commit e75324b

33 files changed

+201
-274
lines changed

doc/rule-descriptions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
| label-title-only | Ensures that every form element is not solely labeled using the title or aria-describedby attributes | cat.forms, best-practice | true |
3535
| label | Ensures every form element has a label | cat.forms, wcag2a, wcag332, wcag131, section508, section508.22.n | true |
3636
| landmark-main-is-top-level | The main landmark should not be contained in another landmark | best-practice | true |
37-
| landmark-no-more-than-one-banner | A banner landmark identifies site-oriented content at the beginning of each page within a website | best-practice | true |
38-
| landmark-no-more-than-one-contentinfo | A contentinfo landmark is a way to identify common information at the bottom of each page within a website | best-practice | true |
37+
| landmark-no-duplicate-banner | Ensures the document has no more than one banner landmark | best-practice | true |
38+
| landmark-no-duplicate-contentinfo | Ensures the document has no more than one contentinfo landmark | best-practice | true |
3939
| landmark-one-main | Ensures a navigation point to the primary content of the page. If the page contains iframes, each iframe should contain either no main landmarks or just one. | best-practice | true |
4040
| layout-table | Ensures presentational <table> elements do not use <th>, <caption> elements or the summary attribute | cat.semantics, wcag2a, wcag131 | true |
4141
| link-in-text-block | Links can be distinguished without relying on color | cat.color, experimental, wcag2a, wcag141 | true |

lib/checks/keyboard/has-no-more-than-one-banner.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

lib/checks/keyboard/has-no-more-than-one-banner.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/checks/keyboard/has-no-more-than-one-contentinfo.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

lib/checks/keyboard/has-no-more-than-one-contentinfo.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/checks/keyboard/has-no-more-than-one-main.js

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"id": "page-no-duplicate-banner",
3+
"evaluate": "page-no-duplicate.js",
4+
"options": {
5+
"selector": "header:not([role]), [role=banner]",
6+
"nativeScopeFilter": "article, aside, main, nav, section"
7+
},
8+
"metadata": {
9+
"impact": "moderate",
10+
"messages": {
11+
"pass": "Document has no more than one banner landmark",
12+
"fail": "Document has more than one banner landmark"
13+
}
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"id": "page-no-duplicate-contentinfo",
3+
"evaluate": "page-no-duplicate.js",
4+
"options": {
5+
"selector": "footer:not([role]), [role=contentinfo]",
6+
"nativeScopeFilter": "article, aside, main, nav, section"
7+
},
8+
"metadata": {
9+
"impact": "moderate",
10+
"messages": {
11+
"pass": "Document has no more than one contentinfo landmark",
12+
"fail": "Document has more than one contentinfo landmark"
13+
}
14+
}
15+
}

lib/checks/keyboard/has-no-more-than-one-main.json renamed to lib/checks/keyboard/page-no-duplicate-main.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
2-
"id": "has-no-more-than-one-main",
3-
"evaluate": "has-no-more-than-one-main.js",
2+
"id": "page-no-duplicate-main",
3+
"evaluate": "page-no-duplicate.js",
4+
"options": {
5+
"selector": "main:not([role]), [role='main']"
6+
},
47
"metadata": {
58
"impact": "moderate",
69
"messages": {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
if (!options || !options.selector || typeof options.selector !== 'string') {
2+
throw new TypeError('visible-in-page requires options.selector to be a string');
3+
}
4+
5+
let elms = axe.utils.querySelectorAll(virtualNode, options.selector);
6+
7+
// Filter elements that, within certain contexts, don't map their role.
8+
// e.g. a <footer> inside a <main> is not a banner, but in the <body> context it is
9+
if (typeof options.nativeScopeFilter === 'string') {
10+
elms = elms.filter(elm => {
11+
return (elm.actualNode.hasAttribute('role') ||
12+
!axe.commons.dom.findUpVirtual(elm, options.nativeScopeFilter));
13+
});
14+
}
15+
16+
this.relatedNodes(elms.map(elm => elm.actualNode));
17+
18+
return elms.length <= 1;

0 commit comments

Comments
 (0)