fix(role): hidden pseudos should not contribute to accessible name (#32251)
This commit is contained in:
parent
d5a7495041
commit
571f25a7d3
|
|
@ -375,7 +375,8 @@ function getPseudoContent(element: Element, pseudo: '::before' | '::after') {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPseudoContentImpl(pseudoStyle: CSSStyleDeclaration | undefined) {
|
function getPseudoContentImpl(pseudoStyle: CSSStyleDeclaration | undefined) {
|
||||||
if (!pseudoStyle)
|
// Note: all browsers ignore display:none and visibility:hidden pseudos.
|
||||||
|
if (!pseudoStyle || pseudoStyle.display === 'none' || pseudoStyle.visibility === 'hidden')
|
||||||
return '';
|
return '';
|
||||||
const content = pseudoStyle.content;
|
const content = pseudoStyle.content;
|
||||||
if ((content[0] === '\'' && content[content.length - 1] === '\'') ||
|
if ((content[0] === '\'' && content[content.length - 1] === '\'') ||
|
||||||
|
|
|
||||||
|
|
@ -475,6 +475,26 @@ test('should ignore stylesheet from hidden aria-labelledby subtree', async ({ pa
|
||||||
expect.soft(await getNameAndRole(page, 'input')).toEqual({ role: 'textbox', name: 'hello' });
|
expect.soft(await getNameAndRole(page, 'input')).toEqual({ role: 'textbox', name: 'hello' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should not include hidden pseudo into accessible name', async ({ page }) => {
|
||||||
|
await page.setContent(`
|
||||||
|
<style>
|
||||||
|
span:before {
|
||||||
|
content: 'world';
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
div:after {
|
||||||
|
content: 'bye';
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<a href="http://example.com">
|
||||||
|
<span>hello</span>
|
||||||
|
<div>hello</div>
|
||||||
|
</a>
|
||||||
|
`);
|
||||||
|
expect.soft(await getNameAndRole(page, 'a')).toEqual({ role: 'link', name: 'hello hello' });
|
||||||
|
});
|
||||||
|
|
||||||
function toArray(x: any): any[] {
|
function toArray(x: any): any[] {
|
||||||
return Array.isArray(x) ? x : [x];
|
return Array.isArray(x) ? x : [x];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue