chore: account for the aria disabled parent (#35430)
This commit is contained in:
parent
26b9441d86
commit
effb64cdf4
|
@ -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) {
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue