From fcc66aef833b8c7546921800e09cbb2096ef9601 Mon Sep 17 00:00:00 2001 From: Marco Moretti Date: Thu, 20 Aug 2020 17:43:00 +0200 Subject: [PATCH] fix: accessibility name when title is empty (#394) Co-authored-by: Sebastian Silbermann --- .changeset/gentle-lamps-perform.md | 7 +++++++ sources/__tests__/accessible-name.js | 1 + sources/accessible-name-and-description.ts | 6 +++++- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .changeset/gentle-lamps-perform.md diff --git a/.changeset/gentle-lamps-perform.md b/.changeset/gentle-lamps-perform.md new file mode 100644 index 00000000..38fca6ab --- /dev/null +++ b/.changeset/gentle-lamps-perform.md @@ -0,0 +1,7 @@ +--- +"dom-accessibility-api": patch +--- + +Ignore `title` attribute if it is empty. + +Previously `` would wrongly compute an empty name. diff --git a/sources/__tests__/accessible-name.js b/sources/__tests__/accessible-name.js index 5449dd7a..ad2c3ac8 100644 --- a/sources/__tests__/accessible-name.js +++ b/sources/__tests__/accessible-name.js @@ -304,6 +304,7 @@ test.each([ ], // https://www.w3.org/TR/svg-aam-1.0/ [`greek rho`, "greek rho"], + [``, "click me"], ])(`test #%#`, testMarkup); test("text nodes are not concatenated by space", () => { diff --git a/sources/accessible-name-and-description.ts b/sources/accessible-name-and-description.ts index 24c3a6f6..d7396a08 100644 --- a/sources/accessible-name-and-description.ts +++ b/sources/accessible-name-and-description.ts @@ -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; }