Skip to content

Commit e9b598c

Browse files
committed
fix(dom): handle empty aria-describedby attribute in getAccessibleDescription function
1 parent 382f08d commit e9b598c

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

packages/dom/src/lib/helpers/helpers.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,28 @@ function normalizeText(text: string): string {
7979
}
8080

8181
export function getAccessibleDescription(actual: Element): string {
82-
const ariaDescribedBy = actual.getAttribute("aria-describedby") || "";
83-
const descriptionIds = ariaDescribedBy
84-
.split(/\s+/)
85-
.filter(Boolean);
86-
87-
if (descriptionIds.length === 0) {
82+
const ariaDescribedBy = actual.getAttribute("aria-describedby");
83+
84+
if (!ariaDescribedBy) {
8885
return "";
8986
}
87+
88+
const descriptionIds = ariaDescribedBy.split(/\s+/).filter(Boolean);
9089

9190
const getElementText = (id: string): string | null => {
9291
const element = actual.ownerDocument.getElementById(id);
93-
return element?.textContent || null;
92+
93+
if (!element || !element.textContent) {
94+
return null;
95+
}
96+
97+
return element.textContent;
9498
};
9599

96-
return normalizeText(
97-
descriptionIds
98-
.map(getElementText)
99-
.filter((text): text is string => text !== null)
100-
.join(" "),
101-
);
100+
const combinedText = descriptionIds
101+
.map(getElementText)
102+
.filter((text): text is string => text !== null)
103+
.join(" ");
104+
105+
return normalizeText(combinedText);
102106
}

0 commit comments

Comments
 (0)