-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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(selection-model): de/select multiple values at the same time #7001
feat(selection-model): de/select multiple values at the same time #7001
Conversation
src/cdk/collections/selection.ts
Outdated
@@ -162,6 +164,13 @@ export class SelectionModel<T> { | |||
this._selection.forEach(value => this._unmarkSelected(value)); | |||
} | |||
} | |||
|
|||
/** Throws an error if multiple values are passed into a selection model with a single value. */ | |||
private _warnMultipleValuesForSingleSelection(values: T[]) { |
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 don't think the name is too accurate since it'll throw an error, not warn.
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.
Done.
src/cdk/collections/selection.ts
Outdated
|
||
/** Throws an error if multiple values are passed into a selection model with a single value. */ | ||
export function throwMultipleValuesInSingleSelectionError() { | ||
throw Error('Cannot pass multiple values into SelectionModel with single-value mode.'); |
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.
Since it is only being used in one place, consider moving this it into _warnMultipleValuesForSingleSelection
?
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 have a convention that we create functions for these errors and re-export the Error object.
e.g in https://github.com/angular/material2/blob/master/src/lib/select/select-errors.ts#L28
Updating to follow that convention
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.
Those errors are in a function so we can use them in tests. If it's a one-off, it's fine to have it inline.
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.
LGTM, one nit. Add label when ready.
src/cdk/collections/selection.ts
Outdated
@@ -182,6 +185,6 @@ export class SelectionChange<T> { | |||
} | |||
|
|||
/** Throws an error if multiple values are passed into a selection model with a single 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.
Comment is inaccurate now. It returns an error instead of throwing it.
6615c9a
to
b629c15
Compare
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.
LGTM
Adds support for passing multiple values to the SelectionModel at the same time. This feature is described in the JSDoc already, but just wasn't implemented yet. This functionality gives us more control about the `onChange` event, which will otherwise fire every time if for example multiple values need to be selected.
b629c15
to
980ce23
Compare
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Adds support for passing multiple values to the SelectionModel at the same time. This feature is described in the JSDoc already, but just wasn't implemented yet.
This functionality gives us more control about the
onChange
event, which will otherwise fire every time if for example multiple values need to be selected.Related to #6896