fix(role): ignore invalid `aria-labelledby` attributes (#33667)
This commit is contained in:
Родитель
ecf6f27159
Коммит
6e19bc341f
|
@ -383,7 +383,11 @@ export function getAriaLabelledByElements(element: Element): Element[] | null {
|
|||
const ref = element.getAttribute('aria-labelledby');
|
||||
if (ref === 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) {
|
||||
|
|
|
@ -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' });
|
||||
});
|
||||
|
||||
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[] {
|
||||
return Array.isArray(x) ? x : [x];
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче