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
23 changes: 23 additions & 0 deletions libs/core/multi-combobox/multi-combobox.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,29 @@ describe('MultiComboBox component', () => {
expect(propagateChangeSpy).toHaveBeenCalled();
});

it('should not move focus to search field when deselecting all items', () => {
const focusToSearchFieldSpy = jest.spyOn(<any>component, '_focusToSearchField');
const item = component._suggestions()[0];

// Select an item first
component._toggleSelection(item);
fixture.detectChanges();

expect(item.selected).toBe(true);
expect(component._selectedSuggestions().length).toEqual(1);

// Toggle selection to deselect the only item
component._toggleSelection(item);
fixture.detectChanges();

// Verify item was deselected
expect(item.selected).toBe(false);
expect(component._selectedSuggestions().length).toEqual(0);

// Verify that _focusToSearchField was NOT called
expect(focusToSearchFieldSpy).not.toHaveBeenCalled();
});

it('should select and unselect all items', () => {
const selectEvent = new KeyboardEvent('keydown', {
keyCode: A,
Expand Down
4 changes: 0 additions & 4 deletions libs/core/multi-combobox/multi-combobox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,6 @@ export class MultiComboboxComponent<T = any> extends BaseMultiCombobox<T> implem

this._propagateChange(fromTokenCloseClick);

if (!this._selectedSuggestions().length) {
this._focusToSearchField();
}

this._cd.detectChanges();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,24 @@ describe('MultiComboboxComponent default values', () => {
expect(multiCombobox._suggestions.length).toEqual(component.dataSource.length);
expect(multiCombobox._selectedSuggestions.length).toEqual(component.selectedItems.length);
});

it('should not move focus to search field when deselecting all items', () => {
const focusToSearchFieldSpy = jest.spyOn(<any>multiCombobox, '_focusToSearchField');
const item = multiCombobox._suggestions[0];

// Ensure we start with a selected item
expect(item.selected).toBe(true);
expect(multiCombobox._selectedSuggestions.length).toEqual(1);

// Toggle selection to deselect the only item
multiCombobox.toggleSelection(item);
fixture.detectChanges();

// Verify item was deselected
expect(item.selected).toBe(false);
expect(multiCombobox._selectedSuggestions.length).toEqual(0);

// Verify that _focusToSearchField was NOT called
expect(focusToSearchFieldSpy).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,6 @@ export class MultiComboboxComponent extends BaseMultiCombobox implements OnInit,

this._propagateChange();

if (!this._selectedSuggestions.length) {
this._focusToSearchField();
}

this.detectChanges();
}

Expand Down
Loading