-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(material-experimental/mdc-slide-toggle): switch to non-deprecate…
…d styles (#23143) Switches the MDC-based slide toggle to the non-deprecated MDC styles. Notable changes: * New markup which uses a `button` instead of an `input` for the button. * New icons inside the slide toggle's thumb. Technically we could opt out of them, but I think that they look better and they help with accessibility for color-blind users. * New theming system that uses a flat list of variables. There is a fallback for IE11, but I opted not to include it for now, because of the upcoming deprecation and the fact that the component is in experimental. * The component has some slightly different colors and it supports more states (e.g. hover). * Due to the switch from `input` to `button`, the `required` input is basically a noop now.
- Loading branch information
Showing
15 changed files
with
318 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 73 additions & 55 deletions
128
src/material-experimental/mdc-slide-toggle/_slide-toggle-theme.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 42 additions & 24 deletions
66
src/material-experimental/mdc-slide-toggle/slide-toggle.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,51 @@ | ||
<div class="mdc-form-field" | ||
[class.mdc-form-field--align-end]="labelPosition == 'before'"> | ||
<div class="mdc-switch mat-mdc-switch" #switch> | ||
<button | ||
class="mdc-switch" | ||
role="switch" | ||
type="button" | ||
[class.mdc-switch--selected]="checked" | ||
[class.mdc-switch--unselected]="!checked" | ||
[tabIndex]="tabIndex" | ||
[disabled]="disabled" | ||
[attr.id]="buttonId" | ||
[attr.name]="name" | ||
[attr.aria-label]="ariaLabel" | ||
[attr.aria-labelledby]="_getAriaLabelledBy()" | ||
[attr.aria-describedby]="ariaDescribedby" | ||
[attr.aria-required]="required" | ||
(click)="_handleClick($event)" | ||
#switch> | ||
<div class="mdc-switch__track"></div> | ||
<div class="mdc-switch__thumb-underlay mat-mdc-focus-indicator"> | ||
<div class="mat-mdc-slide-toggle-ripple" mat-ripple | ||
[matRippleTrigger]="switch" | ||
[matRippleDisabled]="disableRipple || disabled" | ||
[matRippleCentered]="true" | ||
[matRippleAnimation]="_rippleAnimation"></div> | ||
<div class="mdc-switch__thumb"> | ||
<input #input class="mdc-switch__native-control" type="checkbox" | ||
role="switch" | ||
[id]="inputId" | ||
[required]="required" | ||
[tabIndex]="tabIndex" | ||
[checked]="checked" | ||
[disabled]="disabled" | ||
[attr.name]="name" | ||
[attr.aria-checked]="checked.toString()" | ||
[attr.aria-label]="ariaLabel" | ||
[attr.aria-labelledby]="ariaLabelledby" | ||
[attr.aria-describedby]="ariaDescribedby" | ||
(change)="_onChangeEvent($event)" | ||
(click)="_onInputClick($event)"> | ||
<div class="mdc-switch__handle-track"> | ||
<div class="mdc-switch__handle"> | ||
<div class="mdc-switch__shadow"> | ||
<div class="mdc-elevation-overlay"></div> | ||
</div> | ||
<div class="mdc-switch__ripple"> | ||
<div class="mat-mdc-slide-toggle-ripple mat-mdc-focus-indicator" mat-ripple | ||
[matRippleTrigger]="switch" | ||
[matRippleDisabled]="disableRipple || disabled" | ||
[matRippleCentered]="true" | ||
[matRippleAnimation]="_rippleAnimation"></div> | ||
</div> | ||
<div class="mdc-switch__icons"> | ||
<svg class="mdc-switch__icon mdc-switch__icon--on" viewBox="0 0 24 24"> | ||
<path d="M19.69,5.23L8.96,15.96l-4.23-4.23L2.96,13.5l6,6L21.46,7L19.69,5.23z" /> | ||
</svg> | ||
<svg class="mdc-switch__icon mdc-switch__icon--off" viewBox="0 0 24 24"> | ||
<path d="M20 13H4v-2h16v2z" /> | ||
</svg> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</button> | ||
|
||
<label [for]="inputId"> | ||
<!-- | ||
Clicking on the label will trigger another click event from the button. | ||
Stop propagation here so other listeners further up in the DOM don't execute twice. | ||
--> | ||
<label [for]="buttonId" [attr.id]="_labelId" (click)="$event.stopPropagation()"> | ||
<ng-content></ng-content> | ||
</label> | ||
</div> |
Oops, something went wrong.