Skip to content

Commit c501480

Browse files
authored
Merge pull request #7518 from IgniteUI/mvenkov/input-with-null-value-9.0
Should not correctly set undefined or null as input value 9.0
2 parents ad5ffaf + 8f4a758 commit c501480

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

projects/igniteui-angular/src/lib/directives/input/input.directive.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,29 @@ describe('IgxInput', () => {
615615
expect(inputGroup.element.nativeElement.classList.contains(INPUT_GROUP_INVALID_CSS_CLASS)).toBe(false);
616616
expect(inputGroup.element.nativeElement.classList.contains(INPUT_GROUP_VALID_CSS_CLASS)).toBe(false);
617617
});
618+
619+
it('should not set null or undefined as input value', () => {
620+
const fixture = TestBed.createComponent(InputComponent);
621+
fixture.detectChanges();
622+
623+
const igxInput = fixture.componentInstance.igxInput;
624+
expect(igxInput.value).toBe('');
625+
626+
igxInput.value = undefined;
627+
expect(igxInput.value).toBe('');
628+
629+
igxInput.value = null;
630+
expect(igxInput.value).toBe('');
631+
632+
igxInput.value = 0;
633+
expect(igxInput.value).toBe('0');
634+
635+
igxInput.value = false;
636+
expect(igxInput.value).toBe('false');
637+
638+
igxInput.value = 'Test';
639+
expect(igxInput.value).toBe('Test');
640+
});
618641
});
619642

620643
@Component({ template: `

projects/igniteui-angular/src/lib/directives/input/input.directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class IgxInputDirective implements AfterViewInit, OnDestroy {
7474
*/
7575
@Input('value')
7676
set value(value: any) {
77-
this.nativeElement.value = value;
77+
this.nativeElement.value = value ?? '';
7878
this.checkValidity();
7979
}
8080
/**

0 commit comments

Comments
 (0)