Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

feat(checkbox): add indeterminate checkbox support #7643

Closed
wants to merge 1 commit into from

Conversation

DerekLouie
Copy link
Contributor

@gmoothart @ErinCoughlan @jelbourn @ThomasBurleson

This adds the indeterminate state to md-checkbox.

Please Review.

References issue #1912

indetcheckbox
indetunselectall
indetselectall

@DerekLouie DerekLouie added needs: review This PR is waiting on review from the team EOC labels Mar 19, 2016
@DerekLouie DerekLouie added this to the EOC - Q1 milestone Mar 19, 2016
@DerekLouie DerekLouie self-assigned this Mar 19, 2016
@DerekLouie DerekLouie force-pushed the inteterminateCheckbox branch 3 times, most recently from cce1af7 to 9d0b1b7 Compare March 19, 2016 00:44
@ThomasBurleson
Copy link
Contributor

@DerekLouie - please note that we have a PR and issue naming convention.

e.g. (for this PR) feat(checkbox): add indeterminate checkbox support

if(ngModelCtrl.$viewValue) {
element.addClass(CHECKED_CSS);
} else {
element.removeClass(CHECKED_CSS);
}
}

function setIndeterminateState() {
var isIndeterminate = element.attr('indeterminate') === 'true' || false;
Copy link
Member

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)

Copy link
Contributor Author

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)

Copy link
Member

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?

Copy link
Contributor

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 == true
  • intermediate="true" == true
  • intermediate="false" == false

@EladBezalel @ThomasBurleson Please correct me if I'm wrong here.

Copy link
Member

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)

Copy link
Contributor Author

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 :(

@DerekLouie DerekLouie changed the title Adding the inteterminate checkbox state to md-checkbox. feat(checkbox): add indeterminate checkbox support Mar 21, 2016
@DerekLouie DerekLouie force-pushed the inteterminateCheckbox branch 2 times, most recently from f402acc to bcc2d8c Compare March 21, 2016 21:32
@DerekLouie
Copy link
Contributor Author

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


describe('with the indeterminate attribute', function() {

it('should set indeterminate attr to false by default', function() {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@DerekLouie DerekLouie force-pushed the inteterminateCheckbox branch 3 times, most recently from 630c02b to 6c36b21 Compare March 21, 2016 22:29
* @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
Copy link
Contributor

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 ?

Copy link
Contributor Author

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.

@ErinCoughlan
Copy link
Contributor

LGTM.

Make sure to change your commit message to be:
feat(checkbox): add indeterminate checkbox support

@DerekLouie
Copy link
Contributor Author

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isIndeterminate = newValue !== false;

@ErinCoughlan
Copy link
Contributor

@jelbourn Should there be aria-checked somewhere in here? I didn't see it in the initial code, so is it not helpful?

@DerekLouie
Copy link
Contributor Author

Took out some extra code and also added some code to dictate the 'aria-checked' attribute.

Please review.

function setIndeterminateState(newValue) {
isIndeterminate = newValue !== false;
if (isIndeterminate) {
element.attr('aria-checked', 'mixed');
Copy link
Contributor

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.

Copy link
Contributor Author

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..

Copy link
Member

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

@DerekLouie
Copy link
Contributor Author

Hello All,

I have addressed all the aforementioned comments, please review at your earliest convenience!

Best,

Derek

@devversion
Copy link
Member

LGTM now, aside one comment.

@DerekLouie
Copy link
Contributor Author

Apologies, there have been quite a few comments, I will happily address it, which comment?

@DerekLouie
Copy link
Contributor Author

Ahh thank you @devversion, fixed the comment.

@jelbourn
Copy link
Member

LGTM

@@ -251,4 +251,21 @@
cursor: default;
}

&.md-indeterminate ._md-icon {
Copy link
Member

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

Copy link
Contributor Author

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?

@ErinCoughlan ErinCoughlan added pr: merge ready This PR is ready for a caretaker to review and removed needs: review This PR is waiting on review from the team labels Mar 25, 2016
@crisbeto
Copy link
Member

LGTM

@ThomasBurleson
Copy link
Contributor

@DerekLouie - really nice feature. I LOVE this demo:

screen shot 2016-03-30 at 12 27 27 pm

gmoothart pushed a commit to gmoothart/material that referenced this pull request Apr 5, 2016
jelbourn pushed a commit that referenced this pull request Apr 28, 2016
ThomasBurleson pushed a commit that referenced this pull request May 17, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr: merge ready This PR is ready for a caretaker to review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants