Skip to content

Commit f042258

Browse files
committed
fixup! fix(cdk-experimental/ui-patterns): listbox selection fixes
1 parent be499e6 commit f042258

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.value()).toEqual([1, 2, 3]);
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: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,7 @@ export class ListSelection<T extends ListSelectionItem<V>, V> {
6060

6161
// TODO: Need to discuss when to drop this.
6262
this._anchor();
63-
64-
const orderedValues = [];
65-
for (const {value} of this.inputs.items()) {
66-
if (this.inputs.value().includes(value()) || item.value() === value()) {
67-
orderedValues.push(value());
68-
}
69-
}
70-
this.inputs.value.set(orderedValues);
63+
this.inputs.value.update(values => values.concat(item.value()));
7164
}
7265

7366
/** Deselects the item at the current active index. */

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ describe('Listbox Pattern', () => {
248248
listbox.onKeydown(down());
249249
listbox.onKeydown(up({shift: true}));
250250
listbox.onKeydown(up({shift: true}));
251-
expect(listbox.inputs.value()).toEqual(['Apple', 'Apricot']);
251+
expect(listbox.inputs.value()).toEqual(['Apricot', 'Apple']);
252252
});
253253

254254
it('should select contiguous items from the most recently selected item to the focused item on Shift + Space (or Enter)', () => {
@@ -331,7 +331,7 @@ describe('Listbox Pattern', () => {
331331
listbox.onKeydown(down());
332332
listbox.onKeydown(up({shift: true}));
333333
listbox.onKeydown(up({shift: true}));
334-
expect(listbox.inputs.value()).toEqual(['Apple', 'Apricot', 'Banana']);
334+
expect(listbox.inputs.value()).toEqual(['Banana', 'Apricot', 'Apple']);
335335
});
336336

337337
it('should select contiguous items from the most recently selected item to the focused item on Shift + Space (or Enter)', () => {
@@ -349,7 +349,7 @@ describe('Listbox Pattern', () => {
349349
listbox.onKeydown(down({control: true}));
350350
listbox.onKeydown(down());
351351
listbox.onKeydown(home({control: true, shift: true}));
352-
expect(listbox.inputs.value()).toEqual(['Apple', 'Apricot', 'Banana', 'Blackberry']);
352+
expect(listbox.inputs.value()).toEqual(['Blackberry', 'Apple', 'Apricot', 'Banana']);
353353
});
354354

355355
it('should select the focused option and all options down to the last option on Ctrl + Shift + End', () => {

0 commit comments

Comments
 (0)