Skip to content

Commit

Permalink
feat: toHaveAccessibleErrorMessage should handle multiple aria-errorm…
Browse files Browse the repository at this point in the history
…essage references
  • Loading branch information
pengooseDev committed Dec 14, 2024
1 parent 3d84d6d commit aec6180
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions packages/playwright-core/src/server/injected/roleUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,18 +473,15 @@ export function getElementAccessibleErrorMessage(element: Element): string {
if (isAriaInvalid) {
const errorMessageId = element.getAttribute('aria-errormessage');
if (errorMessageId) {
// Ensure the ID is valid (no whitespace)
if (!/\s+/.test(errorMessageId)) {
// Retrieve the element referenced by aria-errormessage.
const errorElement = element.ownerDocument.getElementById(errorMessageId);
if (errorElement) {
accessibleErrorMessage = asFlatString(
getTextAlternativeInternal(errorElement, {
visitedElements: new Set(),
embeddedInDescribedBy: { element: errorElement, hidden: isElementHiddenForAria(errorElement) },
})
);
}
const errorMessages = getIdRefs(element, errorMessageId);
if (errorMessages.length) {
const parts = errorMessages.map(errorMessage => asFlatString(
getTextAlternativeInternal(errorMessage, {
visitedElements: new Set(),
embeddedInDescribedBy: { element: errorMessage, hidden: isElementHiddenForAria(errorMessage) },
})
));
accessibleErrorMessage = parts.join(' ').trim();
}
}
}
Expand Down

0 comments on commit aec6180

Please sign in to comment.