-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
feat(): add slide-toggle component. #362
feat(): add slide-toggle component. #362
Conversation
a7ae61c
to
16c1cf9
Compare
@devversion Now needs rebasing on my mega change #384. Feel free to ping me if you run into any issues. |
de7f505
to
1950cd5
Compare
@jelbourn Done :) |
<div class="md-container"> | ||
<div class="md-bar"></div> | ||
<div class="md-thumb-container"> | ||
<div class="md-thumb"></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.
For the slide-toggle, we want to drive the component with an underlying native checkbox, similar to what @robertmesserle is doing in #415 (since the slide-toggle is pretty much just a checkbox with a different appearance).
This gives you the accessibility and keyboard interaction for free.
c7c45d9
to
92a56cf
Compare
## Theming | ||
A slide-toggle is default using the `accent` palette for its styling. | ||
|
||
Modifiying the color on a `slide-toggle` can be easily done, by using the following classes. |
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.
Need to update the readme for color="..."
9f8d20c
to
32d7aac
Compare
[tabIndex]="tabIndex" | ||
[checked]="checked" | ||
[disabled]="disabled" | ||
[attr.name]="name" |
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.
Should be able to just do [name]
without the attr.
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.
This is a good point. I also had that before. But this will cause issues with a falsy value.
For example, if the user, uses [name]="myName", and the
myNameproperty is set to
null` will result in
<input name="null">
If you want to confirm it yourself. You can try setting $0.name = null
in the Dev Tools on an input.
The advantage of [attr.name]
is, that it removes the attribute, when it's falsy.
Same as in #447
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.
After trying it out, you're right, attr.name
is what we want for now.
if (this.checked !== !!value) { | ||
this._checked = value; | ||
this.onChange(this._checked); | ||
this._change.emit(this._checked); |
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.
One of the things I ran into recently was that checkbox and radio were firing change
events for their initial value, which is unexpected. I fixed it by adding an _isInitialized
field and setting it to true in ngAfterContentInit
and then gating the emit
on _isInitialized
being true. This also prevents ng-pristine
from being immediately changed to ng-dirty
on first load. (see my PR #443).
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 tested that, and covered all possible situations by tests.
The issue, with firing events for the initial seems to be a more specific problem with the
I cannot reproduce this issue with the slide-toggle
component.
I also noticed that as well some days ago - But it seems like I fixed it anyway.
I guess it's covered by this check in the setter.
Once an initial value get's emitted, then we compare the old value with the new one.
Which will be false in those cases.
if (this.checked !== !!value) {
Fantastic PR! Just a few comments for things that are in-flight for existing components. |
a26be92
to
218860e
Compare
`MdSlideToggle` is a two-state control, which can be also called `switch` | ||
|
||
### Screenshots | ||
![image](https://raw.githubusercontent.com/angular/code.material.angularjs.org/master/material2_assets/slide-toggle/toggles.png) |
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 added a hosted asset for you:
https://material.angularjs.org/material2_assets/slide-toggle/toggles.png
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.
Haha 😄 I was already using that, but over the GitHub user content
LGTM, just needs a rebase and to update the readme asset. |
218860e
to
eee0766
Compare
@jelbourn Everything done |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
First step; Basic Skeleton for the Slide Toggle Component.
Adressed in other PR's