Skip to content

Commit

Permalink
fix: accessibility name when title is empty (#394)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Silbermann <silbermann.sebastian@gmail.com>
  • Loading branch information
marcosvega91 and eps1lon authored Aug 20, 2020
1 parent 5a44722 commit fcc66ae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changeset/gentle-lamps-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"dom-accessibility-api": patch
---

Ignore `title` attribute if it is empty.

Previously `<button title="">Hello, Dave!</button>` would wrongly compute an empty name.
1 change: 1 addition & 0 deletions sources/__tests__/accessible-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ test.each([
],
// https://www.w3.org/TR/svg-aam-1.0/
[`<svg data-test><title><em>greek</em> rho</title></svg>`, "greek rho"],
[`<button title="" data-test>click me</button>`, "click me"],
])(`test #%#`, testMarkup);

test("text nodes are not concatenated by space", () => {
Expand Down
6 changes: 5 additions & 1 deletion sources/accessible-name-and-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,11 @@ export function computeTextAlternative(
}

const titleAttribute = node.getAttributeNode("title");
if (titleAttribute !== null && !consultedNodes.has(titleAttribute)) {
if (
titleAttribute !== null &&
titleAttribute.value.trim() !== "" &&
!consultedNodes.has(titleAttribute)
) {
consultedNodes.add(titleAttribute);
return titleAttribute.value;
}
Expand Down

0 comments on commit fcc66ae

Please sign in to comment.