Skip to content

Commit 1ea31cc

Browse files
committed
fixup! feat(cdk-experimental/ui-patterns): add grid selection behavior
1 parent d355787 commit 1ea31cc

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/cdk-experimental/ui-patterns/behaviors/grid-selection/grid-selection.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,15 @@ describe('GridSelection', () => {
681681
gridSelection.deselectAll();
682682
expect(gridSelection.inputs.value()).toEqual(['(0,0)']);
683683
});
684+
685+
it('should deselect values that are not in the grid', () => {
686+
const {gridSelection} = createGridSelection({
687+
cells: gridA,
688+
value: signal(['(4,4)', '(5,5)']),
689+
});
690+
gridSelection.deselectAll();
691+
expect(gridSelection.inputs.value()).toEqual([]);
692+
});
684693
});
685694

686695
describe('toggleAll()', () => {

src/cdk-experimental/ui-patterns/behaviors/grid-selection/grid-selection.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,12 @@ export class GridSelection<T extends GridSelectionCell<V>, V> {
8585

8686
/** Deselects all items in the grid. */
8787
deselectAll() {
88-
for (const row of this.inputs.cells()) {
89-
for (const cell of row) {
90-
this.deselect(cell);
88+
const cells = this.inputs.cells().flat();
89+
cells.forEach(cell => this.deselect(cell));
90+
91+
for (const value of this.inputs.value()) {
92+
if (!cells.some(cell => cell.value() === value)) {
93+
this.inputs.value.update(values => values.filter(v => v !== value));
9194
}
9295
}
9396
}

0 commit comments

Comments
 (0)