Skip to content

Commit

Permalink
feat: support aria-description as descriptor (#934)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Silbermann <silbermann.sebastian@gmail.com>
  • Loading branch information
alonidiom and eps1lon committed May 25, 2023
1 parent 1149a4b commit 8acefc3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
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

0 comments on commit 8acefc3

Please sign in to comment.