-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
109 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { AccessibilityError } from "../scanner"; | ||
import { querySelectorAll, hasAccessibleText } from "../utils"; | ||
|
||
const text = "ARIA button, link, and menuitem must have an accessible name"; | ||
const url = "https://dequeuniversity.com/rules/axe/4.4/aria-command-name"; | ||
|
||
/* | ||
<div role="link" id="al" aria-label="Name"></div> | ||
<div role="button" id="alb" aria-labelledby="labeldiv"></div> | ||
<div role="menuitem" id="combo" aria-label="Aria Name">Name</div> | ||
<div role="link" id="title" title="Title"></div> | ||
*/ | ||
|
||
export default function (el: Element): AccessibilityError[] { | ||
const errors = []; | ||
const elements = querySelectorAll( | ||
'[role="link"], [role="button"], [role="menuitem"]', | ||
el, | ||
); | ||
|
||
if (el.matches('[role="link"], [role="button"], [role="menuitem"]')) { | ||
elements.push(el as HTMLAudioElement); | ||
} | ||
|
||
for (const element of elements) { | ||
if (hasAccessibleText(element)) continue; | ||
errors.push({ element, text, url }); | ||
} | ||
return errors; | ||
} |
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,53 @@ | ||
import { fixture, expect } from "@open-wc/testing"; | ||
import { Scanner } from "../src/scanner"; | ||
import rule from "../src/rules/aria-command-name"; | ||
|
||
const scanner = new Scanner([rule]); | ||
|
||
const passes = [ | ||
`<div role="link" id="al" aria-label="Name"></div>`, | ||
`<div> | ||
<div id="labeldiv">Name</div> | ||
<div role="button" id="alb" aria-labelledby="labeldiv"></div> | ||
</div>`, | ||
`<div role="menuitem" id="combo" aria-label="Aria Name">Name</div>`, | ||
`<div role="link" id="title" title="Title"></div> | ||
`, | ||
]; | ||
|
||
const violations = [ | ||
`<div role="link" id="empty"></div>`, | ||
`<div role="button" id="alempty" aria-label=""></div>`, | ||
`<div role="menuitem" id="albmissing" aria-labelledby="nonexistent"></div>`, | ||
`<div><div role="link" id="albempty" aria-labelledby="emptydiv"></div> | ||
<div id="emptydiv"></div></div>`, | ||
]; | ||
|
||
describe("aria-command-name", async function () { | ||
for (const markup of passes) { | ||
const el = await fixture(markup); | ||
it(el.outerHTML, async function () { | ||
const results = (await scanner.scan(el)).map(({ text, url }) => { | ||
return { text, url }; | ||
}); | ||
|
||
expect(results).to.be.empty; | ||
}); | ||
} | ||
|
||
for (const markup of violations) { | ||
const el = await fixture(markup); | ||
it(el.outerHTML, async function () { | ||
const results = (await scanner.scan(el)).map(({ text, url }) => { | ||
return { text, url }; | ||
}); | ||
|
||
expect(results).to.eql([ | ||
{ | ||
text: "ARIA button, link, and menuitem must have an accessible name", | ||
url: "https://dequeuniversity.com/rules/axe/4.4/aria-command-name", | ||
}, | ||
]); | ||
}); | ||
} | ||
}); |