Skip to content

Commit 8acefc3

Browse files
alonidiomeps1lon
andauthored
feat: support aria-description as descriptor (#934)
Co-authored-by: Sebastian Silbermann <[email protected]>
1 parent 1149a4b commit 8acefc3

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

.changeset/two-eagles-peel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"dom-accessibility-api": patch
3+
---
4+
5+
Support `aria-description` as descriptor

sources/__tests__/accessible-description.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ describe("wpt copies", () => {
5959
`<a data-test href="#" aria-label="California" title="San Francisco" >United States</a>`,
6060
"San Francisco",
6161
],
62+
[
63+
`<button data-test href="#" aria-description="Paid feature">Deploy</button>`,
64+
"Paid feature",
65+
],
66+
[
67+
`<img src="foo.jpg" data-test alt="test" aria-description="bar" aria-describedby="t1"><span id="t1" role="presentation">foo</span>`,
68+
"foo",
69+
],
6270
])(`#%#`, (markup, expectedAccessibleDescription) => {
6371
expect(markup).toRenderIntoDocumentAccessibleDescription(
6472
expectedAccessibleDescription

sources/accessible-description.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@ export function computeAccessibleDescription(
2424

2525
// TODO: Technically we need to make sure that node wasn't used for the accessible name
2626
// This causes `description_1.0_combobox-focusable-manual` to fail
27-
//
27+
28+
// https://w3c.github.io/aria/#aria-description
29+
// mentions that aria-description should only be calculated if aria-describedby didn't provide
30+
// a description
31+
if (description === "") {
32+
const ariaDescription = root.getAttribute("aria-description");
33+
description = ariaDescription === null ? "" : ariaDescription;
34+
}
35+
2836
// https://www.w3.org/TR/html-aam-1.0/#accessible-name-and-description-computation
2937
// says for so many elements to use the `title` that we assume all elements are considered
3038
if (description === "") {

sources/getRole.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ function hasGlobalAriaAttributes(element: Element, role: string): boolean {
9090
"aria-busy",
9191
"aria-controls",
9292
"aria-current",
93+
"aria-description",
9394
"aria-describedby",
9495
"aria-details",
9596
// "disabled",

0 commit comments

Comments
 (0)