Skip to content

fix(material/menu): clear static aria attributes from host node #21231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/material-experimental/mdc-menu/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,26 @@ describe('MDC-based MatMenu', () => {
.toBe(overlayContainerElement.querySelector('.mat-mdc-menu-panel'));
}));

it('should clear the static aria-label from the menu host', () => {
const fixture = createComponent(StaticAriaLabelMenu);
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('mat-menu').hasAttribute('aria-label')).toBe(false);
});

it('should clear the static aria-labelledby from the menu host', () => {
const fixture = createComponent(StaticAriaLabelledByMenu);
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('mat-menu').hasAttribute('aria-labelledby'))
.toBe(false);
});

it('should clear the static aria-describedby from the menu host', () => {
const fixture = createComponent(StaticAriaDescribedbyMenu);
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('mat-menu').hasAttribute('aria-describedby'))
.toBe(false);
});

describe('lazy rendering', () => {
it('should be able to render the menu content lazily', fakeAsync(() => {
const fixture = createComponent(SimpleLazyMenu);
Expand Down Expand Up @@ -2603,3 +2623,21 @@ class LazyMenuWithOnPush {
})
class InvalidRecursiveMenu {
}


@Component({
template: '<mat-menu aria-label="label"></mat-menu>'
})
class StaticAriaLabelMenu {}


@Component({
template: '<mat-menu aria-labelledby="some-element"></mat-menu>'
})
class StaticAriaLabelledByMenu {}


@Component({
template: '<mat-menu aria-describedby="some-element"></mat-menu>'
})
class StaticAriaDescribedbyMenu {}
5 changes: 5 additions & 0 deletions src/material-experimental/mdc-menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export const MAT_MENU_SCROLL_STRATEGY_FACTORY_PROVIDER: Provider = {
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
exportAs: 'matMenu',
host: {
'[attr.aria-label]': 'null',
'[attr.aria-labelledby]': 'null',
'[attr.aria-describedby]': 'null',
},
animations: [
matMenuAnimations.transformMenu,
matMenuAnimations.fadeInItems
Expand Down
38 changes: 38 additions & 0 deletions src/material/menu/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,26 @@ describe('MatMenu', () => {
expect(document.activeElement).toBe(overlayContainerElement.querySelector('.mat-menu-panel'));
}));

it('should clear the static aria-label from the menu host', () => {
const fixture = createComponent(StaticAriaLabelMenu);
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('mat-menu').hasAttribute('aria-label')).toBe(false);
});

it('should clear the static aria-labelledby from the menu host', () => {
const fixture = createComponent(StaticAriaLabelledByMenu);
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('mat-menu').hasAttribute('aria-labelledby'))
.toBe(false);
});

it('should clear the static aria-describedby from the menu host', () => {
const fixture = createComponent(StaticAriaDescribedbyMenu);
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('mat-menu').hasAttribute('aria-describedby'))
.toBe(false);
});

describe('lazy rendering', () => {
it('should be able to render the menu content lazily', fakeAsync(() => {
const fixture = createComponent(SimpleLazyMenu);
Expand Down Expand Up @@ -2692,3 +2712,21 @@ class LazyMenuWithOnPush {
})
class InvalidRecursiveMenu {
}


@Component({
template: '<mat-menu aria-label="label"></mat-menu>'
})
class StaticAriaLabelMenu {}


@Component({
template: '<mat-menu aria-labelledby="some-element"></mat-menu>'
})
class StaticAriaLabelledByMenu {}


@Component({
template: '<mat-menu aria-describedby="some-element"></mat-menu>'
})
class StaticAriaDescribedbyMenu {}
5 changes: 5 additions & 0 deletions src/material/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,11 @@ export class _MatMenuBase implements AfterContentInit, MatMenuPanel<MatMenuItem>
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
exportAs: 'matMenu',
host: {
'[attr.aria-label]': 'null',
'[attr.aria-labelledby]': 'null',
'[attr.aria-describedby]': 'null',
},
animations: [
matMenuAnimations.transformMenu,
matMenuAnimations.fadeInItems
Expand Down