Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/dev-app/slide-toggle/slide-toggle-demo.html
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would there be a mat-slide-toggle without a label? Are there good use cases for it? Should it just be removed instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nvm

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<mat-slide-toggle labelPosition="before" [disabled]="firstToggle">Disable Bound</mat-slide-toggle>
<mat-slide-toggle labelPosition="before" hideIcon [(ngModel)]="firstToggle">No icon</mat-slide-toggle>

<p>With no label.</p>

<mat-slide-toggle aria-label="Toggle only" hideLabel color="primary" [(ngModel)]="firstToggle" />

<p>Example where the slide toggle is required inside of a form.</p>

<form #form="ngForm" (ngSubmit)="onFormSubmit()">
Expand Down
5 changes: 5 additions & 0 deletions src/material/slide-toggle/slide-toggle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ $fallbacks: m3-slide-toggle.get-tokens();
}
}

// Ensure no label element (with a click handler) present to ensure hidden from screen readers.
label:empty {
display: none;
}

.mdc-switch__track {
overflow: hidden;
position: relative;
Expand Down
2 changes: 2 additions & 0 deletions src/material/slide-toggle/slide-toggle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,8 @@ describe('MatSlideToggle with forms', () => {

it('should update checked state on click if control is checked initially', fakeAsync(() => {
fixture = TestBed.createComponent(SlideToggleWithModel);
fixture.detectChanges();

slideToggle = fixture.debugElement.query(By.directive(MatSlideToggle))!.componentInstance;
labelElement = fixture.debugElement.query(By.css('label'))!.nativeElement;

Expand Down
Loading