Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,34 @@ describe('List Selection', () => {
selection.selectOne(); // [0]
expect(selection.inputs.value()).toEqual([0]);
});

it('should do nothing if the current active item is disabled', () => {
const selection = getSelection({multi: signal(true)});
const items = selection.inputs.items() as TestItem[];

selection.inputs.focusManager.focus(items[1]);
selection.select();
expect(selection.inputs.value()).toEqual([1]);

selection.inputs.focusManager.focus(items[0]);
items[0].disabled.set(true);
selection.selectOne();
expect(selection.inputs.value()).toEqual([1]);
});

it('should not select an item if the list is not multiselectable and not all items are deselected', () => {
const selection = getSelection({multi: signal(false)});
const items = selection.inputs.items() as TestItem[];

selection.inputs.focusManager.focus(items[1]);
selection.select();
expect(selection.inputs.value()).toEqual([1]);

items[1].disabled.set(true);
selection.inputs.focusManager.focus(items[2]);
selection.selectOne();
expect(selection.inputs.value()).toEqual([1]);
});
});

describe('#selectRange', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,16 @@ export class ListSelection<T extends ListSelectionItem<V>, V> {

/** Sets the selection to only the current active item. */
selectOne() {
if (this.inputs.focusManager.activeItem().disabled()) {
return;
}

this.deselectAll();

if (this.inputs.value().length > 0 && !this.inputs.multi()) {
return;
}

this.select();
}

Expand Down
2 changes: 1 addition & 1 deletion src/cdk-experimental/ui-patterns/listbox/listbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ describe('Listbox Pattern', () => {
listbox.onKeydown(down());
expect(listbox.inputs.value()).toEqual(['Apricot']);
listbox.onKeydown(down());
expect(listbox.inputs.value()).toEqual([]);
expect(listbox.inputs.value()).toEqual(['Apricot']);
listbox.onKeydown(down());
expect(listbox.inputs.value()).toEqual(['Blackberry']);
});
Expand Down
2 changes: 1 addition & 1 deletion src/cdk-experimental/ui-patterns/tabs/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export class TabListPattern {

/** Handles updating selection for the tablist. */
private _select(opts?: SelectOptions) {
if (opts?.select && !this.focusManager.activeItem().disabled()) {
if (opts?.select) {
this.selection.selectOne();
this.expansionManager.open(this.focusManager.activeItem());
}
Expand Down
Loading