mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(role): ignore invalid aria-labelledby attributes (#33667)
This commit is contained in:
parent
ecf6f27159
commit
6e19bc341f
@ -383,7 +383,11 @@ export function getAriaLabelledByElements(element: Element): Element[] | null {
|
|||||||
const ref = element.getAttribute('aria-labelledby');
|
const ref = element.getAttribute('aria-labelledby');
|
||||||
if (ref === null)
|
if (ref === null)
|
||||||
return null;
|
return null;
|
||||||
return getIdRefs(element, ref);
|
const refs = getIdRefs(element, ref);
|
||||||
|
// step 2b:
|
||||||
|
// "if the current node has an aria-labelledby attribute that contains at least one valid IDREF"
|
||||||
|
// Therefore, if none of the refs match an element, we consider aria-labelledby to be missing.
|
||||||
|
return refs.length ? refs : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function allowsNameFromContent(role: string, targetDescendant: boolean) {
|
function allowsNameFromContent(role: string, targetDescendant: boolean) {
|
||||||
|
|||||||
@ -495,6 +495,16 @@ test('should not include hidden pseudo into accessible name', async ({ page }) =
|
|||||||
expect.soft(await getNameAndRole(page, 'a')).toEqual({ role: 'link', name: 'hello hello' });
|
expect.soft(await getNameAndRole(page, 'a')).toEqual({ role: 'link', name: 'hello hello' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should ignore invalid aria-labelledby', async ({ page }) => {
|
||||||
|
await page.setContent(`
|
||||||
|
<label>
|
||||||
|
<span>Text here</span>
|
||||||
|
<input type=text aria-labelledby="does-not-exist">
|
||||||
|
</label>
|
||||||
|
`);
|
||||||
|
expect.soft(await getNameAndRole(page, 'input')).toEqual({ role: 'textbox', name: 'Text here' });
|
||||||
|
});
|
||||||
|
|
||||||
function toArray(x: any): any[] {
|
function toArray(x: any): any[] {
|
||||||
return Array.isArray(x) ? x : [x];
|
return Array.isArray(x) ? x : [x];
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user