Skip to content

Commit 3ba45d5

Browse files
committed
feat(material/slide-togge): Add option to hide label
1 parent 11cee77 commit 3ba45d5

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/dev-app/slide-toggle/slide-toggle-demo.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
<mat-slide-toggle labelPosition="before" [disabled]="firstToggle">Disable Bound</mat-slide-toggle>
1313
<mat-slide-toggle labelPosition="before" hideIcon [(ngModel)]="firstToggle">No icon</mat-slide-toggle>
1414

15+
<p>With no label.</p>
16+
17+
<mat-slide-toggle aria-label="Toggle only" hideLabel color="primary" [(ngModel)]="firstToggle" />
18+
1519
<p>Example where the slide toggle is required inside of a form.</p>
1620

1721
<form #form="ngForm" (ngSubmit)="onFormSubmit()">

src/material/slide-toggle/slide-toggle.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@
5757
Clicking on the label will trigger another click event from the button.
5858
Stop propagation here so other listeners further up in the DOM don't execute twice.
5959
-->
60-
<label class="mdc-label" [for]="buttonId" [attr.id]="_labelId" (click)="$event.stopPropagation()">
61-
<ng-content></ng-content>
62-
</label>
60+
@if (!hideLabel) {
61+
<label class="mdc-label" [for]="buttonId" [attr.id]="_labelId" (click)="$event.stopPropagation()">
62+
<ng-content></ng-content>
63+
</label>
64+
}
6365
</div>

src/material/slide-toggle/slide-toggle.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ export class MatSlideToggle
183183
this._changeDetectorRef.markForCheck();
184184
}
185185

186+
/** Whether to hide the icon inside of the slide toggle. */
187+
@Input({transform: booleanAttribute}) hideLabel: boolean;
188+
186189
/** Whether to hide the icon inside of the slide toggle. */
187190
@Input({transform: booleanAttribute}) hideIcon: boolean;
188191

0 commit comments

Comments
 (0)