Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(combos): change valid property type to exposed IgxInputState #13646

Merged
merged 3 commits into from
Nov 8, 2023
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
35 changes: 10 additions & 25 deletions projects/igniteui-angular/src/lib/combo/combo.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,6 @@ export enum DataTypes {
PRIMARYKEY = 'valueKey'
}

export enum IgxComboState {
/**
* Combo with initial state.
*/
INITIAL = IgxInputState.INITIAL,
/**
* Combo with valid state.
*/
VALID = IgxInputState.VALID,
/**
* Combo with invalid state.
*/
INVALID = IgxInputState.INVALID
}

/** The filtering criteria to be applied on data search */
export interface IComboFilteringOptions {
/** Defines filtering case-sensitivity */
Expand Down Expand Up @@ -792,7 +777,7 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
* let valid = this.combo.valid;
* ```
*/
public get valid(): IgxComboState {
public get valid(): IgxInputState {
return this._valid;
}

Expand All @@ -801,12 +786,12 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
*
* ```typescript
* // set
* this.combo.valid = IgxComboState.INVALID;
* this.combo.valid = IgxInputState.INVALID;
* ```
*/
public set valid(valid: IgxComboState) {
public set valid(valid: IgxInputState) {
this._valid = valid;
this.comboInput.valid = IgxInputState[IgxComboState[valid]];
this.comboInput.valid = valid;
}

/**
Expand Down Expand Up @@ -941,7 +926,7 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
protected _displayKey: string;
protected _remoteSelection = {};
protected _resourceStrings = getCurrentResourceStrings(ComboResourceStringsEN);
protected _valid = IgxComboState.INITIAL;
protected _valid = IgxInputState.INITIAL;
protected ngControl: NgControl = null;
protected destroy$ = new Subject<any>();
protected _onTouchedCallback: () => void = noop;
Expand Down Expand Up @@ -1250,9 +1235,9 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
if (this.collapsed) {
this._onTouchedCallback();
if (this.ngControl && this.ngControl.invalid) {
this.valid = IgxComboState.INVALID;
this.valid = IgxInputState.INVALID;
} else {
this.valid = IgxComboState.INITIAL;
this.valid = IgxInputState.INITIAL;
}
}
}
Expand All @@ -1270,13 +1255,13 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
protected onStatusChanged = () => {
if (this.ngControl && this.isTouchedOrDirty && !this.disabled) {
if (this.hasValidators && (!this.collapsed || this.inputGroup.isFocused)) {
this.valid = this.ngControl.valid ? IgxComboState.VALID : IgxComboState.INVALID;
this.valid = this.ngControl.valid ? IgxInputState.VALID : IgxInputState.INVALID;
} else {
this.valid = this.ngControl.valid ? IgxComboState.INITIAL : IgxComboState.INVALID;
this.valid = this.ngControl.valid ? IgxInputState.INITIAL : IgxInputState.INVALID;
}
} else {
// B.P. 18 May 2021: IgxDatePicker does not reset its state upon resetForm #9526
this.valid = IgxComboState.INITIAL;
this.valid = IgxInputState.INITIAL;
}
this.manageRequiredAsterisk();
};
Expand Down
46 changes: 23 additions & 23 deletions projects/igniteui-angular/src/lib/combo/combo.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { UIInteractions, wait } from '../test-utils/ui-interactions.spec';
import { IgxComboAddItemComponent } from './combo-add-item.component';
import { IgxComboDropDownComponent } from './combo-dropdown.component';
import { IgxComboItemComponent } from './combo-item.component';
import { IComboFilteringOptions, IgxComboState } from './combo.common';
import { IComboFilteringOptions } from './combo.common';
import {
IComboItemAdditionEvent, IComboSearchInputEventArgs, IComboSelectionChangingEventArgs, IgxComboComponent
} from './combo.component';
Expand Down Expand Up @@ -3019,26 +3019,26 @@ describe('igxCombo', () => {
expect(combo.value).toEqual(comboFormReference.value);
expect(combo.selection.length).toEqual(1);
expect(combo.selection[0].field).toEqual('Connecticut');
expect(combo.valid).toEqual(IgxComboState.INITIAL);
expect(combo.valid).toEqual(IgxInputState.INITIAL);
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);
const clearButton = fixture.debugElement.query(By.css(`.${CSS_CLASS_CLEARBUTTON}`));
clearButton.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
fixture.detectChanges();
expect(combo.valid).toEqual(IgxComboState.INVALID);
expect(combo.valid).toEqual(IgxInputState.INVALID);
expect(combo.comboInput.valid).toEqual(IgxInputState.INVALID);

combo.onBlur();
fixture.detectChanges();
expect(combo.valid).toEqual(IgxComboState.INVALID);
expect(combo.valid).toEqual(IgxInputState.INVALID);
expect(combo.comboInput.valid).toEqual(IgxInputState.INVALID);

combo.select([combo.dropdown.items[0], combo.dropdown.items[1]]);
expect(combo.valid).toEqual(IgxComboState.VALID);
expect(combo.valid).toEqual(IgxInputState.VALID);
expect(combo.comboInput.valid).toEqual(IgxInputState.VALID);

combo.onBlur();
fixture.detectChanges();
expect(combo.valid).toEqual(IgxComboState.INITIAL);
expect(combo.valid).toEqual(IgxInputState.INITIAL);
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);
});
it('should properly initialize when used as a form control - without validators', () => {
Expand All @@ -3051,26 +3051,26 @@ describe('igxCombo', () => {
expect(combo.value).toEqual(comboFormReference.value);
expect(combo.selection.length).toEqual(1);
expect(combo.selection[0].field).toEqual('Connecticut');
expect(combo.valid).toEqual(IgxComboState.INITIAL);
expect(combo.valid).toEqual(IgxInputState.INITIAL);
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);
const clearButton = fixture.debugElement.query(By.css(`.${CSS_CLASS_CLEARBUTTON}`));
clearButton.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
fixture.detectChanges();
expect(combo.valid).toEqual(IgxComboState.INITIAL);
expect(combo.valid).toEqual(IgxInputState.INITIAL);
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);

combo.onBlur();
fixture.detectChanges();
expect(combo.valid).toEqual(IgxComboState.INITIAL);
expect(combo.valid).toEqual(IgxInputState.INITIAL);
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);

combo.select([combo.dropdown.items[0], combo.dropdown.items[1]]);
expect(combo.valid).toEqual(IgxComboState.INITIAL);
expect(combo.valid).toEqual(IgxInputState.INITIAL);
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);

combo.onBlur();
fixture.detectChanges();
expect(combo.valid).toEqual(IgxComboState.INITIAL);
expect(combo.valid).toEqual(IgxInputState.INITIAL);
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);
});
it('should be possible to be enabled/disabled when used as a form control', () => {
Expand Down Expand Up @@ -3198,32 +3198,32 @@ describe('igxCombo', () => {
inputGroupRequired = fixture.debugElement.query(By.css(`.${CSS_CLASS_INPUTGROUP_REQUIRED}`));
}));
it('should properly initialize when used in a template form control', () => {
expect(combo.valid).toEqual(IgxComboState.INITIAL);
expect(combo.valid).toEqual(IgxInputState.INITIAL);
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);
expect(inputGroupRequired).toBeDefined();
combo.onBlur();
fixture.detectChanges();
expect(combo.valid).toEqual(IgxComboState.INVALID);
expect(combo.valid).toEqual(IgxInputState.INVALID);
expect(combo.comboInput.valid).toEqual(IgxInputState.INVALID);

input.triggerEventHandler('focus', {});
combo.selectAllItems();
fixture.detectChanges();
expect(combo.valid).toEqual(IgxComboState.VALID);
expect(combo.valid).toEqual(IgxInputState.VALID);
expect(combo.comboInput.valid).toEqual(IgxInputState.VALID);

const clearButton = fixture.debugElement.query(By.css(`.${CSS_CLASS_CLEARBUTTON}`));
clearButton.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
fixture.detectChanges();
expect(combo.valid).toEqual(IgxComboState.INVALID);
expect(combo.valid).toEqual(IgxInputState.INVALID);
expect(combo.comboInput.valid).toEqual(IgxInputState.INVALID);
});
it('should properly init with empty array and handle consecutive model changes', fakeAsync(() => {
const model = fixture.debugElement.query(By.directive(NgModel)).injector.get(NgModel);
fixture.componentInstance.values = [];
fixture.detectChanges();
tick();
expect(combo.valid).toEqual(IgxComboState.INITIAL);
expect(combo.valid).toEqual(IgxInputState.INITIAL);
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);
expect(model.valid).toBeFalse();
expect(model.dirty).toBeFalse();
Expand All @@ -3232,7 +3232,7 @@ describe('igxCombo', () => {
fixture.componentInstance.values = ['Missouri'];
fixture.detectChanges();
tick();
expect(combo.valid).toEqual(IgxComboState.INITIAL);
expect(combo.valid).toEqual(IgxInputState.INITIAL);
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);
expect(combo.selection).toEqual([{ field: 'Missouri', region: 'West North Central' }]);
expect(combo.value).toEqual(['Missouri']);
Expand All @@ -3242,7 +3242,7 @@ describe('igxCombo', () => {

fixture.componentInstance.values = ['Missouri', 'Missouri'];
fixture.detectChanges();
expect(combo.valid).toEqual(IgxComboState.INITIAL);
expect(combo.valid).toEqual(IgxInputState.INITIAL);
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);
expect(combo.selection).toEqual([{ field: 'Missouri', region: 'West North Central' }]);
expect(combo.value).toEqual(['Missouri']);
Expand All @@ -3253,7 +3253,7 @@ describe('igxCombo', () => {
fixture.componentInstance.values = null;
fixture.detectChanges();
tick();
expect(combo.valid).toEqual(IgxComboState.INITIAL);
expect(combo.valid).toEqual(IgxInputState.INITIAL);
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);
expect(combo.selection).toEqual([]);
expect(combo.value).toEqual([]);
Expand All @@ -3264,7 +3264,7 @@ describe('igxCombo', () => {

combo.onBlur();
fixture.detectChanges();
expect(combo.valid).toEqual(IgxComboState.INVALID);
expect(combo.valid).toEqual(IgxInputState.INVALID);
expect(combo.comboInput.valid).toEqual(IgxInputState.INVALID);
expect(model.valid).toBeFalse();
expect(model.touched).toBeTrue();
Expand All @@ -3273,7 +3273,7 @@ describe('igxCombo', () => {
fixture.componentInstance.values = ['New Jersey'];
fixture.detectChanges();
tick();
expect(combo.valid).toEqual(IgxComboState.INITIAL);
expect(combo.valid).toEqual(IgxInputState.INITIAL);
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);
expect(combo.selection).toEqual([{ field: 'New Jersey', region: 'Mid-Atlan' }]);
expect(combo.value).toEqual(['New Jersey']);
Expand All @@ -3292,12 +3292,12 @@ describe('igxCombo', () => {
it('should set validity to initial when the form is reset', fakeAsync(() => {
combo.onBlur();
fixture.detectChanges();
expect(combo.valid).toEqual(IgxComboState.INVALID);
expect(combo.valid).toEqual(IgxInputState.INVALID);
expect(combo.comboInput.valid).toEqual(IgxInputState.INVALID);

fixture.componentInstance.form.resetForm();
tick();
expect(combo.valid).toEqual(IgxComboState.INITIAL);
expect(combo.valid).toEqual(IgxInputState.INITIAL);
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);
}));
});
Expand Down
Loading
Loading