Skip to content

Commit 8cc9789

Browse files
committed
fixup! refactor(cdk-experimental/ui-patterns): track list selection by value
1 parent 3906bb5 commit 8cc9789

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

src/cdk-experimental/listbox/listbox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class CdkListbox<V> {
9090
disabled = input(false, {transform: booleanAttribute});
9191

9292
/** The values of the current selected items. */
93-
values = model<V[]>([]);
93+
value = model<V[]>([]);
9494

9595
/** The current index that has been navigated to. */
9696
activeIndex = model<number>(0);

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('List Selection', () => {
5050
return new ListSelection({
5151
items,
5252
navigation,
53-
values: signal<V[]>([]),
53+
value: signal<V[]>([]),
5454
multiselectable: signal(true),
5555
selectionMode: signal('explicit'),
5656
...args,
@@ -64,7 +64,7 @@ describe('List Selection', () => {
6464
const selection = getSelection(items, nav);
6565

6666
selection.select(); // [0]
67-
expect(selection.inputs.values()).toEqual([0]);
67+
expect(selection.inputs.value()).toEqual([0]);
6868
});
6969

7070
it('should select multiple options', () => {
@@ -76,7 +76,7 @@ describe('List Selection', () => {
7676
nav.next();
7777
selection.select(); // [0, 1]
7878

79-
expect(selection.inputs.values()).toEqual([0, 1]);
79+
expect(selection.inputs.value()).toEqual([0, 1]);
8080
});
8181

8282
it('should not select multiple options', () => {
@@ -90,7 +90,7 @@ describe('List Selection', () => {
9090
nav.next();
9191
selection.select(); // [1]
9292

93-
expect(selection.inputs.values()).toEqual([1]);
93+
expect(selection.inputs.value()).toEqual([1]);
9494
});
9595

9696
it('should not select disabled items', () => {
@@ -100,7 +100,7 @@ describe('List Selection', () => {
100100
items()[0].disabled.set(true);
101101

102102
selection.select(); // []
103-
expect(selection.inputs.values()).toEqual([]);
103+
expect(selection.inputs.value()).toEqual([]);
104104
});
105105

106106
it('should do nothing to already selected items', () => {
@@ -111,7 +111,7 @@ describe('List Selection', () => {
111111
selection.select(); // [0]
112112
selection.select(); // [0]
113113

114-
expect(selection.inputs.values()).toEqual([0]);
114+
expect(selection.inputs.value()).toEqual([0]);
115115
});
116116
});
117117

@@ -121,7 +121,7 @@ describe('List Selection', () => {
121121
const nav = getNavigation(items);
122122
const selection = getSelection(items, nav);
123123
selection.deselect(); // []
124-
expect(selection.inputs.values().length).toBe(0);
124+
expect(selection.inputs.value().length).toBe(0);
125125
});
126126

127127
it('should not deselect disabled items', () => {
@@ -133,7 +133,7 @@ describe('List Selection', () => {
133133
items()[0].disabled.set(true);
134134
selection.deselect(); // [0]
135135

136-
expect(selection.inputs.values()).toEqual([0]);
136+
expect(selection.inputs.value()).toEqual([0]);
137137
});
138138
});
139139

@@ -144,7 +144,7 @@ describe('List Selection', () => {
144144
const selection = getSelection(items, nav);
145145

146146
selection.toggle(); // [0]
147-
expect(selection.inputs.values()).toEqual([0]);
147+
expect(selection.inputs.value()).toEqual([0]);
148148
});
149149

150150
it('should deselect a selected item', () => {
@@ -153,7 +153,7 @@ describe('List Selection', () => {
153153
const selection = getSelection(items, nav);
154154
selection.select(); // [0]
155155
selection.toggle(); // []
156-
expect(selection.inputs.values().length).toBe(0);
156+
expect(selection.inputs.value().length).toBe(0);
157157
});
158158
});
159159

@@ -163,15 +163,15 @@ describe('List Selection', () => {
163163
const nav = getNavigation(items);
164164
const selection = getSelection(items, nav);
165165
selection.selectAll();
166-
expect(selection.inputs.values()).toEqual([0, 1, 2, 3, 4]);
166+
expect(selection.inputs.value()).toEqual([0, 1, 2, 3, 4]);
167167
});
168168

169169
it('should do nothing if a list is not multiselectable', () => {
170170
const items = getItems([0, 1, 2, 3, 4]);
171171
const nav = getNavigation(items);
172172
const selection = getSelection(items, nav);
173173
selection.selectAll();
174-
expect(selection.inputs.values()).toEqual([0, 1, 2, 3, 4]);
174+
expect(selection.inputs.value()).toEqual([0, 1, 2, 3, 4]);
175175
});
176176
});
177177

@@ -181,7 +181,7 @@ describe('List Selection', () => {
181181
const nav = getNavigation(items);
182182
const selection = getSelection(items, nav);
183183
selection.deselectAll(); // []
184-
expect(selection.inputs.values().length).toBe(0);
184+
expect(selection.inputs.value().length).toBe(0);
185185
});
186186
});
187187

@@ -196,7 +196,7 @@ describe('List Selection', () => {
196196
nav.next();
197197
selection.selectFromPrevSelectedItem(); // [0, 1, 2]
198198

199-
expect(selection.inputs.values()).toEqual([0, 1, 2]);
199+
expect(selection.inputs.value()).toEqual([0, 1, 2]);
200200
});
201201

202202
it('should select all items from an anchor at a higher index', () => {
@@ -212,7 +212,7 @@ describe('List Selection', () => {
212212
selection.selectFromPrevSelectedItem(); // [3, 1, 2]
213213

214214
// TODO(wagnermaciel): Order the values when inserting them.
215-
expect(selection.inputs.values()).toEqual([3, 1, 2]);
215+
expect(selection.inputs.value()).toEqual([3, 1, 2]);
216216
});
217217
});
218218
});

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export interface ListSelectionInputs<T extends ListSelectionItem<V>, V> {
2727
/** Whether multiple items in the list can be selected at once. */
2828
multiselectable: SignalLike<boolean>;
2929

30-
/** The values of the current selected items. */
31-
values: WritableSignalLike<V[]>;
30+
/** The current value of the list selection. */
31+
value: WritableSignalLike<V[]>;
3232

3333
/** The selection strategy used by the list. */
3434
selectionMode: SignalLike<'follow' | 'explicit'>;
@@ -50,7 +50,7 @@ export class ListSelection<T extends ListSelectionItem<V>, V> {
5050
select(item?: T) {
5151
item = item ?? this.inputs.items()[this.inputs.navigation.inputs.activeIndex()];
5252

53-
if (item.disabled() || this.inputs.values().includes(item.value())) {
53+
if (item.disabled() || this.inputs.value().includes(item.value())) {
5454
return;
5555
}
5656

@@ -60,28 +60,28 @@ export class ListSelection<T extends ListSelectionItem<V>, V> {
6060

6161
// TODO: Need to discuss when to drop this.
6262
this._anchor();
63-
this.inputs.values.update(values => values.concat(item.value()));
63+
this.inputs.value.update(values => values.concat(item.value()));
6464
}
6565

6666
/** Deselects the item at the current active index. */
6767
deselect(item?: T) {
6868
item = item ?? this.inputs.items()[this.inputs.navigation.inputs.activeIndex()];
6969

7070
if (!item.disabled()) {
71-
this.inputs.values.update(values => values.filter(value => value !== item.value()));
71+
this.inputs.value.update(values => values.filter(value => value !== item.value()));
7272
}
7373
}
7474

7575
/** Toggles the item at the current active index. */
7676
toggle() {
7777
const item = this.inputs.items()[this.inputs.navigation.inputs.activeIndex()];
78-
this.inputs.values().includes(item.value()) ? this.deselect() : this.select();
78+
this.inputs.value().includes(item.value()) ? this.deselect() : this.select();
7979
}
8080

8181
/** Toggles only the item at the current active index. */
8282
toggleOne() {
8383
const item = this.inputs.items()[this.inputs.navigation.inputs.activeIndex()];
84-
this.inputs.values().includes(item.value()) ? this.deselect() : this.selectOne();
84+
this.inputs.value().includes(item.value()) ? this.deselect() : this.selectOne();
8585
}
8686

8787
/** Selects all items in the list. */

src/cdk-experimental/ui-patterns/listbox/option.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class OptionPattern<V> {
4949
);
5050

5151
/** Whether the option is selected. */
52-
selected = computed(() => this.listbox()?.selection.inputs.values().includes(this.value()));
52+
selected = computed(() => this.listbox()?.selection.inputs.value().includes(this.value()));
5353

5454
/** Whether the option is disabled. */
5555
disabled: SignalLike<boolean>;

0 commit comments

Comments
 (0)