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

feat(select): Adding check boxes to the multi-select menu #7455

Closed
wants to merge 1 commit into from

Conversation

DerekLouie
Copy link
Contributor

@ErinCoughlan @jelbourn @KarenParker @gmoothart

Please Review.

Adding check boxes to the multi-select menu.

selectcheckboxes

References issue #3244.

@DerekLouie DerekLouie changed the title Adding checkboxes to angular material stuff feat(select): Adding check boxes to the multi-select menu Mar 8, 2016
@DerekLouie DerekLouie added EOC needs: review This PR is waiting on review from the team labels Mar 8, 2016
@DerekLouie DerekLouie added this to the EOC - Q1 milestone Mar 8, 2016
@DerekLouie DerekLouie self-assigned this Mar 8, 2016
@@ -75,3 +75,17 @@ md-select-menu.md-THEME_NAME-theme {
}
}
}

md-select-menu[multiple] {
md-option {
Copy link
Member

Choose a reason for hiding this comment

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

To be consistent, please indent with two spaces, instead of one tab

Copy link
Member

Choose a reason for hiding this comment

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

Yes- the indent should be +2 spaces

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 apologies, my vimrc did not recognize scss and defaulted to 4 spaces. Corrected.

@jelbourn
Copy link
Member

jelbourn commented Mar 8, 2016

The checkbox borders in the screenshot seem exceptionally dark (black?) to me.

@DerekLouie DerekLouie force-pushed the selectPanelCheckbox branch 2 times, most recently from 4379748 to 7e29a30 Compare March 8, 2016 22:35
@DerekLouie
Copy link
Contributor Author

@ErinCoughlan @jelbourn @KarenParker @gmoothart

Please Review.

I have refactored the select menu checkbox CSS to match the md-checkbox css (wherever applicable).

selectcheckboxv2

References issue #3244.

@DerekLouie DerekLouie force-pushed the selectPanelCheckbox branch 2 times, most recently from 703f1db to d23334d Compare March 9, 2016 01:18
@DerekLouie
Copy link
Contributor Author

Going to explore refactoring the checkbox css such that you can use the same classes directly.

Question @jelbourn: Where would prefer I put this css that will be used in both the select, checkbox, and potentially other components?

@jelbourn
Copy link
Member

jelbourn commented Mar 9, 2016

@DerekLouie there should be one single place where the styles for a checkbox lives, and then each other component should consume those styles.

@DerekLouie DerekLouie force-pushed the selectPanelCheckbox branch from d23334d to e37301b Compare March 11, 2016 02:40
@DerekLouie
Copy link
Contributor Author

Hello All,

I have done some scss wizardry to make the applicable md-checkbox styles re-usable in the md-select directive (and beyond?).

Please Review.

Screenshot with RTL look and feel included for completeness.

checkboxesv3

@DerekLouie DerekLouie force-pushed the selectPanelCheckbox branch 2 times, most recently from 0638d8a to 906a1db Compare March 11, 2016 18:31
@KarenParker
Copy link
Contributor

LGTM

1 similar comment
@ErinCoughlan
Copy link
Contributor

LGTM

@DerekLouie DerekLouie force-pushed the selectPanelCheckbox branch from 906a1db to b703dc6 Compare March 11, 2016 18:59
}
}

@mixin checkbox-container(
Copy link
Member

Choose a reason for hiding this comment

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

Add comment explaining what this mixin does

@ThomasBurleson
Copy link
Contributor

@DerekLouie - we definitely need unit test(s) with this PR.

@ThomasBurleson ThomasBurleson added needs: tests and removed needs: review This PR is waiting on review from the team labels Mar 11, 2016
@ThomasBurleson ThomasBurleson added the in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs label Mar 11, 2016
@DerekLouie DerekLouie force-pushed the selectPanelCheckbox branch from b703dc6 to fc21858 Compare March 12, 2016 02:05
@DerekLouie
Copy link
Contributor Author

Hello All,

I have added unit tests. I ran into an issue where element.find('._md-container') returned an empty sqlite object, my wild shot in the dark is that the underscore in the class name messes something up?

I ended up for looping and using some good old native JS to verify the md-checkbox markup is correctly added.

Please Review.

Best,

Derek

@jelbourn
Copy link
Member

@DerekLouie angular.element's .find function only works for element names (which is surprising if you're used to using jQuery). querySelector is the way to go.

if (selectCtrl.isMultiple) {
element.attr('md-checkbox-enabled', '');
if (!checkboxElement) {
checkboxElement = angular.element('<div class="_md-container"><div class="_md-icon"></div></div>');
Copy link
Member

Choose a reason for hiding this comment

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

This isn't there yet; you're still performing the html -> dom operation for every single item, everywhere. The goal is to only do that operation once ever, and then clone the result for each item.

You want to do something like

var CHECKBOX_SELECTION_INDICATOR = 
    angular.element('<div class="_md-container"><div class="_md-icon"></div></div>');

right inside of OptionDirective before the return, and then clone that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe the behaviour you are describing is, in fact, what is going on here.

Actually if I clone element inside of the OptionDirective right before the return statement a new clone will be made every time the md-option directive is invoked (if you put a debugger on line 760 and navigate to the select demo page, you will notice you hit that debugger breakpoint several times).

I have declared the variable at the very top of the file so there should only be one reference present in the code (kept alive in the parent closure), and it is instantiated IFF we have a multi-select (as close to lazy loading as I could manage).

We never clone the element again (if you put a debugger on line 782 and navigate to the select demo page, you will notice you hit that debugger breakpoint only once).

I agree though that I should rename the variable because my intention was to create a constant.

I believe putting that constant at the top of the OptionDirective initially un-initialized but keeping the if statement would make the code more efficient than it was previously, but then detecting if the clone has been created already in other OptionDirective's on the page becomes more difficult..

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I just misread the code. I wouldn't worry too much about the lazy initializing here; the cost of creating the element once at start-up should be pretty small.

@DerekLouie DerekLouie force-pushed the selectPanelCheckbox branch from fc21858 to 3ce1635 Compare March 15, 2016 17:50
@DerekLouie
Copy link
Contributor Author

Hello All,

I have fixed all the aforementioned comments!

Please Review.

Best,

Derek

@DerekLouie DerekLouie force-pushed the selectPanelCheckbox branch from 3ce1635 to e40bff0 Compare March 15, 2016 18:52
@DerekLouie DerekLouie force-pushed the selectPanelCheckbox branch from e40bff0 to 5718b52 Compare March 15, 2016 18:58
@jelbourn
Copy link
Member

LGTM

@jelbourn jelbourn added pr: merge ready This PR is ready for a caretaker to review and removed in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs needs: tests labels Mar 15, 2016
@Bouazizi-Ezzeddine
Copy link

Hi,
In which version these changes are integrated ?

@torontom
Copy link

torontom commented Dec 5, 2016

Can I do it with anguler-material 1.0.0? I only want to make minimum changes to our project, and get the multiple select with check box...

@ThomasBurleson
Copy link
Contributor

This feature is available in v1.1.0 or higher. See the Select Demo Pizza Toppings which uses the multiple attribute: <md-select ng-model="selectedToppings" multiple>

Version 1.0 is almost a year old and many bugs have been fixed since the v1.0.0 release.

@angular angular locked and limited conversation to collaborators Dec 6, 2016
@Splaktar Splaktar modified the milestones: EOC - Q1, 1.1.0 Jul 5, 2019
@Splaktar
Copy link
Member

Splaktar commented Jul 5, 2019

This works for our standard multiple API, but it doesn't work for the undocumented, untested ng-multiple API which was introduced in 0.9.0.

I've opened #11759 to track supporting checkboxes when using ng-multiple="true"

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 type: enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants