Skip to content

Commit 91ea648

Browse files
committed
fix(combo): don't clear items when disabled #8200
1 parent 2b5c0d6 commit 91ea648

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

projects/igniteui-angular/src/lib/combo/combo.component.spec.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { DisplayDensity } from '../core/density';
1919
import { AbsoluteScrollStrategy, ConnectedPositioningStrategy } from '../services/public_api';
2020
import { IgxSelectionAPIService } from '../core/selection';
2121
import { IgxIconService } from '../icon/public_api';
22-
import { CancelableEventArgs } from '../core/utils';
2322

2423
const CSS_CLASS_COMBO = 'igx-combo';
2524
const CSS_CLASS_COMBO_DROPDOWN = 'igx-combo__drop-down';
@@ -602,6 +601,38 @@ describe('igxCombo', () => {
602601
expect(combo.onSearchInput.emit).toHaveBeenCalledTimes(1);
603602
expect(matchSpy).toHaveBeenCalledTimes(1);
604603
});
604+
it('should not open on click if combo is disabled', () => {
605+
combo = new IgxComboComponent(elementRef, mockCdr, mockSelection as any, mockComboService,
606+
mockIconService, null, null, mockInjector);
607+
const dropdown = jasmine.createSpyObj('IgxComboDropDownComponent', ['open', 'close', 'toggle']);
608+
const spyObj = jasmine.createSpyObj('event', ['stopPropagation', 'preventDefault']);
609+
spyOn(mockIconService, 'addSvgIconFromText').and.returnValue(null);
610+
combo.ngOnInit();
611+
combo.dropdown = dropdown;
612+
dropdown.collapsed = true;
613+
614+
combo.disabled = true;
615+
combo.onInputClick(spyObj);
616+
expect(combo.dropdown.collapsed).toBeTruthy();
617+
});
618+
it('should not clear value when combo is disabled', () => {
619+
const selectionService = new IgxSelectionAPIService();
620+
combo = new IgxComboComponent(elementRef, mockCdr, selectionService, mockComboService,
621+
mockIconService, null, null, mockInjector);
622+
const dropdown = jasmine.createSpyObj('IgxComboDropDownComponent', ['selectItem']);
623+
const spyObj = jasmine.createSpyObj('event', ['stopPropagation']);
624+
spyOn(mockIconService, 'addSvgIconFromText').and.returnValue(null);
625+
combo.ngOnInit();
626+
combo.data = data;
627+
combo.dropdown = dropdown;
628+
combo.disabled = true;
629+
spyOnProperty(combo, 'totalItemCount').and.returnValue(combo.data.length);
630+
631+
const item = combo.data.slice(0, 1);
632+
combo.selectItems(item, true);
633+
combo.handleClearItems(spyObj);
634+
expect(combo.value).toEqual(item[0]);
635+
});
605636
});
606637
describe('Initialization and rendering tests: ', () => {
607638
configureTestSuite();
@@ -2541,13 +2572,6 @@ describe('igxCombo', () => {
25412572
expect(combo.valid).toEqual(IgxComboState.INITIAL);
25422573
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);
25432574
});
2544-
it('should not open on click if combo is disabled', () => {
2545-
combo.disabled = true;
2546-
fixture.detectChanges();
2547-
UIInteractions.simulateClickEvent(combo.comboInput.nativeElement);
2548-
fixture.detectChanges();
2549-
expect(combo.dropdown.collapsed).toBeTruthy();
2550-
});
25512575
it('should be possible to be enabled/disabled when used as a form control', () => {
25522576
const form = fixture.componentInstance.reactiveForm;
25532577
const comboFormReference = form.controls.townCombo;

projects/igniteui-angular/src/lib/combo/combo.component.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,11 +1324,13 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
13241324
* @hidden @internal
13251325
*/
13261326
public handleClearItems(event: Event): void {
1327-
this.deselectAllItems(true, event);
1328-
if (this.collapsed) {
1329-
this.getEditElement().focus();
1330-
} else {
1331-
this.focusSearchInput(true);
1327+
if (!this.disabled) {
1328+
this.deselectAllItems(true, event);
1329+
if (this.collapsed) {
1330+
this.getEditElement().focus();
1331+
} else {
1332+
this.focusSearchInput(true);
1333+
}
13321334
}
13331335
event.stopPropagation();
13341336
}

0 commit comments

Comments
 (0)