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: support aria-description as descriptor #934

Merged
merged 2 commits into from
May 25, 2023
Merged
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
5 changes: 5 additions & 0 deletions .changeset/two-eagles-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"dom-accessibility-api": patch
---

Support `aria-description` as descriptor
8 changes: 8 additions & 0 deletions sources/__tests__/accessible-description.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ describe("wpt copies", () => {
`<a data-test href="#" aria-label="California" title="San Francisco" >United States</a>`,
"San Francisco",
],
[
`<button data-test href="#" aria-description="Paid feature">Deploy</button>`,
"Paid feature",
],
[
`<img src="foo.jpg" data-test alt="test" aria-description="bar" aria-describedby="t1"><span id="t1" role="presentation">foo</span>`,
"foo",
],
])(`#%#`, (markup, expectedAccessibleDescription) => {
expect(markup).toRenderIntoDocumentAccessibleDescription(
expectedAccessibleDescription
Expand Down
10 changes: 9 additions & 1 deletion sources/accessible-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ export function computeAccessibleDescription(

// TODO: Technically we need to make sure that node wasn't used for the accessible name
// This causes `description_1.0_combobox-focusable-manual` to fail
//

// https://w3c.github.io/aria/#aria-description
// mentions that aria-description should only be calculated if aria-describedby didn't provide
// a description
if (description === "") {
const ariaDescription = root.getAttribute("aria-description");
description = ariaDescription === null ? "" : ariaDescription;
}

// https://www.w3.org/TR/html-aam-1.0/#accessible-name-and-description-computation
// says for so many elements to use the `title` that we assume all elements are considered
if (description === "") {
Expand Down
1 change: 1 addition & 0 deletions sources/getRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function hasGlobalAriaAttributes(element: Element, role: string): boolean {
"aria-busy",
"aria-controls",
"aria-current",
"aria-description",
"aria-describedby",
"aria-details",
// "disabled",
Expand Down