mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(input): treat number 0 as non-empty (#2245)
This commit is contained in:
@@ -38,6 +38,7 @@ describe('MdInputContainer', function () {
|
||||
MdInputContainerTextTestController,
|
||||
MdInputContainerPasswordTestController,
|
||||
MdInputContainerNumberTestController,
|
||||
MdInputContainerZeroTestController,
|
||||
MdTextareaWithBindings,
|
||||
MdInputContainerWithDisabled,
|
||||
MdInputContainerMissingMdInputTestController
|
||||
@@ -127,6 +128,19 @@ describe('MdInputContainer', function () {
|
||||
expect(el.classList.contains('md-empty')).toBe(false, 'should not be empty');
|
||||
}));
|
||||
|
||||
it('should not treat the number 0 as empty', async(() => {
|
||||
let fixture = TestBed.createComponent(MdInputContainerZeroTestController);
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
|
||||
let el = fixture.debugElement.query(By.css('label')).nativeElement;
|
||||
expect(el).not.toBeNull();
|
||||
expect(el.classList.contains('md-empty')).toBe(false);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should add id', () => {
|
||||
let fixture = TestBed.createComponent(MdInputContainerTextTestController);
|
||||
fixture.detectChanges();
|
||||
@@ -405,6 +419,16 @@ class MdInputContainerPasswordTestController {}
|
||||
})
|
||||
class MdInputContainerNumberTestController {}
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<md-input-container>
|
||||
<input md-input type="number" placeholder="Placeholder" [(ngModel)]="value">
|
||||
</md-input-container>`
|
||||
})
|
||||
class MdInputContainerZeroTestController {
|
||||
value = 0;
|
||||
}
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<md-input-container>
|
||||
|
||||
@@ -118,7 +118,7 @@ export class MdInputDirective implements AfterContentInit {
|
||||
*/
|
||||
@Output() _placeholderChange = new EventEmitter<string>();
|
||||
|
||||
get empty() { return (this.value == null || this.value == '') && !this._isNeverEmpty(); }
|
||||
get empty() { return (this.value == null || this.value === '') && !this._isNeverEmpty(); }
|
||||
|
||||
focused = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user