Components: mat-selection-list: selectAll and deselectAll methods should trigger selectionChange event

Created on 3 Apr 2019  路  7Comments  路  Source: angular/components

selectAll() and deselectAll() methods on MatSelectionList should automatically trigger the selectionChange event.

What is the use-case or motivation for this proposal?

Select some documents from a list.

The MatListOptions have [value] populated with an object containing a number of properties of the document (name, file size, last edited date, expiry date, etc.).
You want to communicate a warning to the user that specifies the number of expired documents in their current selection.
It's easy enough to calculate the number of expired documents in the current selection when the selectionChange event is fired, but if the user decides to selectAll, this event is not triggered, so additional workarounds need to be made to cover this case.

Is there anything else we should know?

P3 materialist has pr

Most helpful comment

What if you have a user interaction wired up to selectAll/deselectAll?

I think it would be nice to have the option to trigger this event without having to write extra code.

How about an optional extra parameter to the selectAll and deselectAll methods which would fire the event?

E.g.

selectAll(fireSelectionChange: boolean = false): void {
  ...
}

All 7 comments

I believe the intention with selectionChange is that it emits only if the option changed as a result of a user interaction and selectAll/deselectAll are programmatic changes.

@crisbeto: Thanks, I see your point.
If this is the case, then I'd want to update the documentation to make this explicitly clear.

Sure, feel free to send in a PR to update the docs.

What if you have a user interaction wired up to selectAll/deselectAll?

I think it would be nice to have the option to trigger this event without having to write extra code.

How about an optional extra parameter to the selectAll and deselectAll methods which would fire the event?

E.g.

selectAll(fireSelectionChange: boolean = false): void {
  ...
}

Was puzzled by this aswell, we expose select all / deselect all buttons to the user
Screenshot 2019-11-28 at 11 43 44

would be nice with an option to fire the change event from these.

Seeing this now- I believe we should emit the event when the change comes from the user pressing Ctrl + A to trigger the select-all / deselect-all (but not when it happens programatically).

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings