-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(material-experimental/mdc-slide-toggle): switch to non-deprecated styles #23143
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I tested the demo (looking at aria-required), I was able to toggle the disabled slide-toggles with the keyboard. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just tried it and I couldn't reproduce. Are you sure that you weren't interacting with the top slide toggle which also changes the value of the disabled one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, I see what happened. With VoiceOver on, screen-reader navigation moved onto the disabled toggle, but browser focus stayed on the enabled one. Nvm. |
||
[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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a comment that explains where these color choices come from? E.g. why is
$on-surface
gray-100/gray-800?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is the part where I had to make some assumptions. The light theme values come from MDC's
$light-theme
variable one-to-one, but since MDC didn't provide a dark theme, I had to come up with the values myself. I did try to follow a pattern (e.g. 800 and 100 are on different ends of the palette), but it's not foolproof.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chatted with the MDC team about the status/plan here. Summary is:
The tokens are split into two parts: system tokens (used across multiple components) and component-specific tokens. I think we should create a Sass file in material/core for the baseline token values, and then create a another file per component with the tokens for that specific spec version. So, something like
We should make sure to comment which values we're just picking ourselves and which we're sourcing from somewhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know which ones are system tokens and which ones are slide toggle-specific? I can make some reasonable guesses, but it would be better if there was a list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The format is a little rough, but this is the stuff currently considered system styles that we care about (there was also some shape stuff that we don't care about yet)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for listing it out. Since this PR is pretty large already, would it be ok if I added these in a follow-up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think that's reasonable, I just want to make sure we do this before adding another component on top of the tokens system