fix(input): treat number 0 as non-empty (#2245)

This commit is contained in:
mmalerba
2016-12-16 15:56:38 -08:00
committed by Jeremy Elbourn
parent 34642ea4ef
commit a8185794f4
2 changed files with 25 additions and 1 deletions
+24
View File
@@ -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>
+1 -1
View File
@@ -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;