Skip to content
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

feat: Add aria-structure-name rule #2431

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions doc/rule-descriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@

## WCAG 2.1 Level A & AA Rules

| Rule ID | Description | Impact | Tags | Issue Type |
| :----------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------- | :------ | :--------------------------- | :--------- |
| [autocomplete-valid](https://dequeuniversity.com/rules/axe/3.5/autocomplete-valid?application=RuleDescription) | Ensure the autocomplete attribute is correct and suitable for the form field | Serious | cat.forms, wcag21aa, wcag135 | failure |
| [avoid-inline-spacing](https://dequeuniversity.com/rules/axe/3.5/avoid-inline-spacing?application=RuleDescription) | Ensure that text spacing set through style attributes can be adjusted with custom stylesheets | Serious | wcag21aa, wcag1412 | failure |
| Rule ID | Description | Impact | Tags | Issue Type |
| :----------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------- | :------ | :--------------------------- | :------------------------- |
| [autocomplete-valid](https://dequeuniversity.com/rules/axe/3.5/autocomplete-valid?application=RuleDescription) | Ensure the autocomplete attribute is correct and suitable for the form field | Serious | cat.forms, wcag21aa, wcag135 | failure |
| [avoid-inline-spacing](https://dequeuniversity.com/rules/axe/3.5/avoid-inline-spacing?application=RuleDescription) | Ensure that text spacing set through style attributes can be adjusted with custom stylesheets | Serious | wcag21aa, wcag1412 | failure |
| [name-author-contents](https://dequeuniversity.com/rules/axe/3.5/name-author-contents?application=RuleDescription) | Ensures elements with ARIA roles that require an accessible name have one from author or contents. | Serious | | failure, needs review |
| [name-author](https://dequeuniversity.com/rules/axe/3.5/name-author?application=RuleDescription) | Ensures elements with ARIA roles that require an accessible name have one from author. | Serious | | failure, needs review |

## Best Practices Rules

Expand Down
17 changes: 17 additions & 0 deletions lib/rules/name-author-contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"id": "name-author-contents",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rule name is a bit vague. Ideally it would tell me what the rule is checking, like button-name or image-alt. name-author-contents does that, but I may not understand what name from author or contents means.

Maybe something like role-required-name? I'm not sure how to appropriately differentiate between having visible text or not.

"selector": "[role=\"treeitem\"]",
"tags": [],
"metadata": {
"description": "Ensures elements with ARIA roles that require an accessible name have one from author or contents.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid talking about author or content here for the same reasons as stated above.

"help": "Required accessible name must be present (author or contents)"
},
"all": [],
"any": [
"aria-label",
"aria-labelledby",
"has-visible-text",
"non-empty-title"
],
"none": []
}
12 changes: 12 additions & 0 deletions lib/rules/name-author.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"id": "name-author",
"selector": "[role=\"tree\"]",
"tags": [],
"metadata": {
"description": "Ensures elements with ARIA roles that require an accessible name have one from author.",
"help": "Required accessible name must be present (author)"
},
"all": [],
"any": ["aria-label", "aria-labelledby", "non-empty-title"],
"none": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div id="labeldiv">Some label</div>
<div id="emptydiv"></div>

<div role="treeitem" id="treeitem-empty"></div>
<div role="treeitem" id="treeitem-text">Name</div>
<div role="treeitem" id="treeitem-al" aria-label="Name"></div>
<div role="treeitem" id="treeitem-alempty" aria-label=""></div>
<div role="treeitem" id="treeitem-alb" aria-labelledby="labeldiv"></div>
<div
role="treeitem"
id="treeitem-albmissing"
aria-labelledby="nonexistent"
></div>
<div role="treeitem" id="treeitem-albempty" aria-labelledby="emptydiv"></div>
<div role="treeitem" id="treeitem-combo" aria-label="Aria Name">Name</div>
<div role="treeitem" id="treeitem-title" title="Title"></div>

<ul role="tree">
<li role="treeitem" id="treeitem-li-named">named</li>
<li role="treeitem" id="treeitem-li-unnamed"></li>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"description": "name-author-contents test",
"rule": "name-author-contents",
"violations": [
["#treeitem-empty"],
["#treeitem-alempty"],
["#treeitem-albmissing"],
["#treeitem-albempty"],
["#treeitem-li-unnamed"]
],
"passes": [
["#treeitem-text"],
["#treeitem-al"],
["#treeitem-alb"],
["#treeitem-combo"],
["#treeitem-title"],
["#treeitem-li-named"]
]
}
15 changes: 15 additions & 0 deletions test/integration/rules/name-author/name-author.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div id="labeldiv">Some label</div>
<div id="emptydiv"></div>

<div role="tree" id="tree-empty"></div>
<div role="tree" id="tree-text">Name</div>
<div role="tree" id="tree-al" aria-label="Name"></div>
<div role="tree" id="tree-alempty" aria-label=""></div>
<div role="tree" id="tree-alb" aria-labelledby="labeldiv"></div>
<div role="tree" id="tree-albmissing" aria-labelledby="nonexistent"></div>
<div role="tree" id="tree-albempty" aria-labelledby="emptydiv"></div>
<div role="tree" id="tree-combo" aria-label="Aria Name">Name</div>
<div role="tree" id="tree-title" title="Title"></div>

<ul role="tree" id="tree-ul-unnamed"></ul>
<ul role="tree" id="tree-ul-named" aria-label="named"></ul>
19 changes: 19 additions & 0 deletions test/integration/rules/name-author/name-author.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"description": "name-author test",
"rule": "name-author",
"violations": [
["#tree-empty"],
["#tree-alempty"],
["#tree-albmissing"],
["#tree-albempty"],
["#tree-ul-unnamed"],
["#tree-text"]
],
"passes": [
["#tree-al"],
["#tree-alb"],
["#tree-combo"],
["#tree-title"],
["#tree-ul-named"]
]
}