Skip to content

Commit 85cc468

Browse files
authored
Merge pull request #8289 from IgniteUI/nalipiev/combo-disabled-clear-9.1.x
fix(combo): don't clear items when disabled #8200
2 parents a80c3fa + 54de322 commit 85cc468

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

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

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

2423
const CSS_CLASS_COMBO = 'igx-combo';
2524
const CSS_CLASS_COMBO_DROPDOWN = 'igx-combo__drop-down';
@@ -564,6 +563,34 @@ describe('igxCombo', () => {
564563
expect(combo.onSearchInput.emit).toHaveBeenCalledTimes(1);
565564
expect(matchSpy).toHaveBeenCalledTimes(1);
566565
});
566+
it('should not open on click if combo is disabled', () => {
567+
combo = new IgxComboComponent({ nativeElement: null }, mockCdr, mockSelection as any, mockComboService, null, mockInjector);
568+
const dropdown = jasmine.createSpyObj('IgxComboDropDownComponent', ['open', 'close', 'toggle']);
569+
const spyObj = jasmine.createSpyObj('event', ['stopPropagation', 'preventDefault']);
570+
combo.ngOnInit();
571+
combo.dropdown = dropdown;
572+
dropdown.collapsed = true;
573+
574+
combo.disabled = true;
575+
combo.onInputClick(spyObj);
576+
expect(combo.dropdown.collapsed).toBeTruthy();
577+
});
578+
it('should not clear value when combo is disabled', () => {
579+
const selectionService = new IgxSelectionAPIService();
580+
combo = new IgxComboComponent({ nativeElement: null }, mockCdr, selectionService, mockComboService, null, mockInjector);
581+
const dropdown = jasmine.createSpyObj('IgxComboDropDownComponent', ['selectItem']);
582+
const spyObj = jasmine.createSpyObj('event', ['stopPropagation']);
583+
combo.ngOnInit();
584+
combo.data = data;
585+
combo.dropdown = dropdown;
586+
combo.disabled = true;
587+
spyOnProperty(combo, 'totalItemCount').and.returnValue(combo.data.length);
588+
589+
const item = combo.data.slice(0, 1);
590+
combo.selectItems(item, true);
591+
combo.handleClearItems(spyObj);
592+
expect(combo.value).toEqual(item[0]);
593+
});
567594
});
568595
describe('Initialization and rendering tests: ', () => {
569596
configureTestSuite();
@@ -2469,13 +2496,6 @@ describe('igxCombo', () => {
24692496
expect(combo.valid).toEqual(IgxComboState.INITIAL);
24702497
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);
24712498
});
2472-
it('should not open on click if combo is disabled', () => {
2473-
combo.disabled = true;
2474-
fixture.detectChanges();
2475-
UIInteractions.simulateClickEvent(combo.comboInput.nativeElement);
2476-
fixture.detectChanges();
2477-
expect(combo.dropdown.collapsed).toBeTruthy();
2478-
});
24792499
it('should be possible to be enabled/disabled when used as a form control', () => {
24802500
const form = fixture.componentInstance.reactiveForm;
24812501
const comboFormReference = form.controls.townCombo;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,9 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
12761276
* @hidden @internal
12771277
*/
12781278
public handleClearItems(event: Event): void {
1279+
if (this.disabled) {
1280+
return;
1281+
}
12791282
this.deselectAllItems(true, event);
12801283
if (this.collapsed) {
12811284
this.getEditElement().focus();

0 commit comments

Comments
 (0)