Skip to content

Commit 0675e05

Browse files
glenstaesandrewseguin
authored andcommitted
feat(collections): add isMultipleSelection function to SelectionModel (#11560)
* feat(collections): Add public getter for _multiple on SelectionModel If your component receives a SelectionModel instance through Input, it was previously not possible to have different behavior based on whether multiple selected items is allowed (e.g.: rendering radio buttons instead of checkboxes). You had to use a second Input property to the component. This pull request allows developers to check the SelectionModel instance property. * Change multiple property to isMultipleSelection function * Fix linting errors * Change description of isMultipleSelection function * Newline to trigger circle ci * Revert: Newline to trigger circle ci
1 parent fa60fe4 commit 0675e05

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/cdk/collections/selection.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,4 +269,12 @@ describe('SelectionModel', () => {
269269
it('should be empty if an empty array is passed for the preselected values', () => {
270270
expect(new SelectionModel(false, []).selected).toEqual([]);
271271
});
272+
273+
it('should be able to determine whether multiple values can be selected', () => {
274+
let multipleSelectionModel = new SelectionModel(true);
275+
expect(multipleSelectionModel.isMultipleSelection()).toBe(true);
276+
277+
let singleSelectionModel = new SelectionModel();
278+
expect(singleSelectionModel.isMultipleSelection()).toBe(false);
279+
});
272280
});

src/cdk/collections/selection.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ export class SelectionModel<T> {
116116
}
117117
}
118118

119+
/**
120+
* Gets whether multiple values can be selected.
121+
*/
122+
isMultipleSelection() {
123+
return this._multiple;
124+
}
125+
119126
/** Emits a change event and clears the records of selected and deselected values. */
120127
private _emitChangeEvent() {
121128
// Clear the selected values so they can be re-cached.

0 commit comments

Comments
 (0)