-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat(checkbox): add indeterminate checkbox support #7643
Conversation
702f828
to
f606d66
Compare
cce1af7
to
9d0b1b7
Compare
@DerekLouie - please note that we have a PR and issue naming convention. e.g. (for this PR) |
if(ngModelCtrl.$viewValue) { | ||
element.addClass(CHECKED_CSS); | ||
} else { | ||
element.removeClass(CHECKED_CSS); | ||
} | ||
} | ||
|
||
function setIndeterminateState() { | ||
var isIndeterminate = element.attr('indeterminate') === 'true' || false; |
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.
@DerekLouie I suggest using the util function, like so
$mdUtil.parseAttributeValue(attr.indeterminate)
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.
Ahh I didn't know that existed, that is handy! I've decided to invalidate this code and change the indeterminate state attributes a bit, but for the sake of brevity..
Interestingly enough this broke the tests b/c $mdUtil.parseAttributeBoolean
will interpret an empty string as true
which we want instead to be interpreted as false
(in the case no value is passed in)
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.
@DerekLouie Yes, that's by intention 😄 . Shouldn't <md-checkbox inderterminate>
work?
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 convention we usually follow is that if the attribute is found with no value, then it is treated as true
as this follows standard HTML attributes (readonly, disabled, etc).
So,
intermediate
== trueintermediate="true"
== trueintermediate="false"
== false
@EladBezalel @ThomasBurleson Please correct me if I'm wrong here.
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.
@topherfangio I agree with you. That's exactly what $mdUtil.parseAttributeValue
does.
But notice, attributes like readonly
, disabled
or required
should ignore false values.
That's why you should use in that case:
$mdUtil.parseAttributeValue(attr, false)
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.
Ahh so it does seem like parseAttributeValue
does not exist. BUT parseAttributeBoolean
does exist. Unfortunately because we can accept a function now as well as a string, we can't use parseAttributeBoolean
:(
f402acc
to
bcc2d8c
Compare
Hello All, I did a minor refactor. The appearance of the indeterminate state is now class based instead of attribute selector based. This allowed me to get rid of the "indeterminate-when" attribute and simplified the api a little. I also fixed the aforementioned comments. Please Review. Best, Derek |
bcc2d8c
to
6328e1b
Compare
|
||
describe('with the indeterminate attribute', function() { | ||
|
||
it('should set indeterminate attr to false by default', function() { |
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 disagree with this test; I believe it should be set to true by default to follow our existing conventions.
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.
Hmm.. that does make a lot of sense :).
Changed, thank you.
630c02b
to
6c36b21
Compare
* @param {expression=} indeterminate-checked-when This determines when the | ||
* indeterminate checkbox should appear checked. The 'indeterminate' state is mutually | ||
* exclusive with the 'checked' and 'unchecked' states. | ||
* @param {expression=} indeterminate-click This gets triggered when the |
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 do not understand the feature here. At first glance, this seems to interfere with ng-click. Or is this an expression that should be invoked with the indeterminant state changes?
e.g. md-change-indeterminant
What is the use case here ?
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.
You are correct, this is not a good attribute.
Previously when I was unsure if a check box could be selected AND indeterminate I thought the click function would be useful for special toggle cases, but in retrospect this was a poor api design decision. Removing it now.
LGTM. Make sure to change your commit message to be: |
e251b35
to
eee8e13
Compare
Changed the commit message, please review again at your earliest convenience! |
element.addClass(CHECKED_CSS); | ||
} else { | ||
element.removeClass(CHECKED_CSS); | ||
} | ||
} | ||
|
||
function setIndeterminateState(newValue) { | ||
isIndeterminate = (newValue === false) ? false : true; |
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.
isIndeterminate = newValue !== false;
@jelbourn Should there be aria-checked somewhere in here? I didn't see it in the initial code, so is it not helpful? |
Took out some extra code and also added some code to dictate the 'aria-checked' attribute. Please review. |
eee8e13
to
8bae422
Compare
function setIndeterminateState(newValue) { | ||
isIndeterminate = newValue !== false; | ||
if (isIndeterminate) { | ||
element.attr('aria-checked', 'mixed'); |
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.
aria-checked is never set for checked or unchecked checkboxes either. If you're going to set it to "mixed", you also should set it to true/false where appropriate.
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.
It actually is set, and accounted for in the tests. It was a little curious though that the code isn't found in this file..
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 believe it's already handled by ngAria
Hello All, I have addressed all the aforementioned comments, please review at your earliest convenience! Best, Derek |
LGTM now, aside one comment. |
Apologies, there have been quite a few comments, I will happily address it, which comment? |
8bae422
to
d63137f
Compare
Ahh thank you @devversion, fixed the comment. |
LGTM |
@@ -251,4 +251,21 @@ | |||
cursor: default; | |||
} | |||
|
|||
&.md-indeterminate ._md-icon { |
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 not related here as well, this is very specific for checkbox
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.
@EladBezalel I could remove the &
. The rule would still be valid and it would be one class less specific?
LGTM |
@DerekLouie - really nice feature. I LOVE this demo: |
@gmoothart @ErinCoughlan @jelbourn @ThomasBurleson
This adds the indeterminate state to md-checkbox.
Please Review.
References issue #1912