chore: account for the aria disabled parent (#35430)

This commit is contained in:
Pavel Feldman 2025-04-03 12:53:01 -07:00 committed by GitHub
parent 26b9441d86
commit effb64cdf4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 4 deletions

View File

@ -1013,18 +1013,19 @@ function belongsToDisabledFieldSet(element: Element): boolean {
return !legendElement || !legendElement.contains(element);
}
function hasExplicitAriaDisabled(element: Element | undefined): boolean {
function hasExplicitAriaDisabled(element: Element | undefined, isAncestor = false): boolean {
if (!element)
return false;
if (kAriaDisabledRoles.includes(getAriaRole(element) || '')) {
if (isAncestor || kAriaDisabledRoles.includes(getAriaRole(element) || '')) {
const attribute = (element.getAttribute('aria-disabled') || '').toLowerCase();
if (attribute === 'true')
return true;
if (attribute === 'false')
return false;
// aria-disabled works across shadow boundaries.
return hasExplicitAriaDisabled(parentElementOrShadowHost(element), true);
}
// aria-disabled works across shadow boundaries.
return hasExplicitAriaDisabled(parentElementOrShadowHost(element));
return false;
}
function getAccessibleNameFromAssociatedLabels(labels: Iterable<HTMLLabelElement>, options: AccessibleNameOptions) {

View File

@ -243,6 +243,22 @@ test('should support disabled', async ({ page }) => {
]);
});
test('should inherit disabled from the ancestor', async ({ page }) => {
await page.setContent(`
<span aria-disabled="true">
<button>Click me!</button>
</span>
`);
await expect(page.locator('button')).toBeDisabled();
await page.setContent(`
<span aria-disabled="true">
<h1>Heading</h1>
</span>
`);
await expect(page.locator('h1')).not.toBeDisabled();
});
test('should support disabled fieldset', async ({ page }) => {
await page.setContent(`
<fieldset disabled>