-
Notifications
You must be signed in to change notification settings - Fork 556
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(material): add select all option to multiselect #1552
feat(material): add select all option to multiselect #1552
Conversation
@aitboudad WIP pull request. The functionality should work as expected. It's just missing some tests. Early feedback welcome 😄. |
a0fd4bb
to
5dce775
Compare
<mat-pseudo-checkbox class="mat-option-pseudo-checkbox" | ||
[state]="state"> | ||
</mat-pseudo-checkbox> | ||
{{ getSelectAllLabel() }} |
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 think we should enforce passing the selectAll label to avoid handling the boolean check, so I propose to use:
{{ to.selectAllOption }}
get value() { return this.formControl.value || []; } | ||
get state() { | ||
if (this.value.length > 0) { | ||
return this.value.length !== this.formFieldControl.options.length |
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 formFieldControl.options
); | ||
} | ||
|
||
getSelectAllLabel() { |
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 should be removed
description: 'Description', | ||
required: true, | ||
multiple: true, | ||
selectAllOption: 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.
pass string instead:
selectAllOption: 'Select All',
Gonna fix them tomorrow 👍 (ehm..later today actually 😅, it's 00:53am here) |
5dce775
to
c32e9d2
Compare
Alright, applied the necessary changes and added a test to verify the option label is properly set 👍 |
LGTM, I let you merge this PR! 🎉🎉 |
c32e9d2
to
a4708ac
Compare
toggleSelectAll() { | ||
this.formControl.setValue( | ||
this.value.length !== this.formFieldControl.options.length | ||
? this.formFieldControl.options.map(x => x.value) |
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 doesn't work with option groups.
I think that would work:
this.formFieldControl.options.map(
x => (x.group ? x.group.map(grp => grp.value) : x.value)
).flat()
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.
@fontsie yep in fact it doesn't . Can u open a new issue. We should work on a PR to fix it
This PR implements the new feature described in #1516 .
selectAllOption
configurationselectAllOption
. String will be used as label if provided