Skip to content
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

fix(slide-toggle): clear static aria attributes from host nodes #17085

Merged
merged 1 commit into from
Sep 18, 2019
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
17 changes: 17 additions & 0 deletions src/material-experimental/mdc-slide-toggle/slide-toggle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('MatSlideToggle without forms', () => {
SlideToggleWithoutLabel,
SlideToggleProjectedLabel,
TextBindingComponent,
SlideToggleWithStaticAriaAttributes,
]
});

Expand Down Expand Up @@ -378,6 +379,15 @@ describe('MatSlideToggle without forms', () => {
expect(testComponent.toggleTriggered).toBe(2, 'Expect toggle twice');
expect(testComponent.dragTriggered).toBe(0);
}));

it('should clear static aria attributes from the host node', () => {
const fixture = TestBed.createComponent(SlideToggleWithStaticAriaAttributes);
fixture.detectChanges();

const host: HTMLElement = fixture.nativeElement.querySelector('mat-slide-toggle');
expect(host.hasAttribute('aria-label')).toBe(false);
expect(host.hasAttribute('aria-labelledby')).toBe(false);
});
});

describe('MatSlideToggle with forms', () => {
Expand Down Expand Up @@ -804,3 +814,10 @@ class SlideToggleProjectedLabel {}
class TextBindingComponent {
text: string = 'Some text';
}

@Component({
template: `
<mat-slide-toggle aria-label="Slide toggle" aria-labelledby="something"></mat-slide-toggle>
`
})
class SlideToggleWithStaticAriaAttributes {}
2 changes: 2 additions & 0 deletions src/material-experimental/mdc-slide-toggle/slide-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export class MatSlideToggleChange {
'class': 'mat-mdc-slide-toggle',
'[id]': 'id',
'[attr.tabindex]': 'null',
'[attr.aria-label]': 'null',
'[attr.aria-labelledby]': 'null',
'[class.mat-primary]': 'color == "primary"',
'[class.mat-accent]': 'color == "accent"',
'[class.mat-warn]': 'color == "warn"',
Expand Down
17 changes: 17 additions & 0 deletions src/material/slide-toggle/slide-toggle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('MatSlideToggle without forms', () => {
SlideToggleWithoutLabel,
SlideToggleProjectedLabel,
TextBindingComponent,
SlideToggleWithStaticAriaAttributes,
],
providers: [
{provide: HAMMER_GESTURE_CONFIG, useFactory: () => gestureConfig = new TestGestureConfig()},
Expand Down Expand Up @@ -767,6 +768,15 @@ describe('MatSlideToggle without forms', () => {
.toContain('mat-slide-toggle-bar-no-side-margin');
});
});

it('should clear static aria attributes from the host node', () => {
const fixture = TestBed.createComponent(SlideToggleWithStaticAriaAttributes);
fixture.detectChanges();

const host: HTMLElement = fixture.nativeElement.querySelector('mat-slide-toggle');
expect(host.hasAttribute('aria-label')).toBe(false);
expect(host.hasAttribute('aria-labelledby')).toBe(false);
});
});

describe('MatSlideToggle with forms', () => {
Expand Down Expand Up @@ -1192,3 +1202,10 @@ class SlideToggleProjectedLabel {}
class TextBindingComponent {
text: string = 'Some text';
}

@Component({
template: `
<mat-slide-toggle aria-label="Slide toggle" aria-labelledby="something"></mat-slide-toggle>
`
})
class SlideToggleWithStaticAriaAttributes {}
2 changes: 2 additions & 0 deletions src/material/slide-toggle/slide-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ const _MatSlideToggleMixinBase:
'[id]': 'id',
// Needs to be `-1` so it can still receive programmatic focus.
'[attr.tabindex]': 'disabled ? null : -1',
'[attr.aria-label]': 'null',
'[attr.aria-labelledby]': 'null',
'[class.mat-checked]': 'checked',
'[class.mat-disabled]': 'disabled',
'[class.mat-slide-toggle-label-before]': 'labelPosition == "before"',
Expand Down