Skip to content

Commit a818579

Browse files
mmalerbajelbourn
authored andcommitted
fix(input): treat number 0 as non-empty (#2245)
1 parent 34642ea commit a818579

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/lib/input/input-container.spec.ts

+24
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ describe('MdInputContainer', function () {
3838
MdInputContainerTextTestController,
3939
MdInputContainerPasswordTestController,
4040
MdInputContainerNumberTestController,
41+
MdInputContainerZeroTestController,
4142
MdTextareaWithBindings,
4243
MdInputContainerWithDisabled,
4344
MdInputContainerMissingMdInputTestController
@@ -127,6 +128,19 @@ describe('MdInputContainer', function () {
127128
expect(el.classList.contains('md-empty')).toBe(false, 'should not be empty');
128129
}));
129130

131+
it('should not treat the number 0 as empty', async(() => {
132+
let fixture = TestBed.createComponent(MdInputContainerZeroTestController);
133+
fixture.detectChanges();
134+
135+
fixture.whenStable().then(() => {
136+
fixture.detectChanges();
137+
138+
let el = fixture.debugElement.query(By.css('label')).nativeElement;
139+
expect(el).not.toBeNull();
140+
expect(el.classList.contains('md-empty')).toBe(false);
141+
});
142+
}));
143+
130144
it('should add id', () => {
131145
let fixture = TestBed.createComponent(MdInputContainerTextTestController);
132146
fixture.detectChanges();
@@ -405,6 +419,16 @@ class MdInputContainerPasswordTestController {}
405419
})
406420
class MdInputContainerNumberTestController {}
407421

422+
@Component({
423+
template: `
424+
<md-input-container>
425+
<input md-input type="number" placeholder="Placeholder" [(ngModel)]="value">
426+
</md-input-container>`
427+
})
428+
class MdInputContainerZeroTestController {
429+
value = 0;
430+
}
431+
408432
@Component({
409433
template: `
410434
<md-input-container>

src/lib/input/input-container.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class MdInputDirective implements AfterContentInit {
118118
*/
119119
@Output() _placeholderChange = new EventEmitter<string>();
120120

121-
get empty() { return (this.value == null || this.value == '') && !this._isNeverEmpty(); }
121+
get empty() { return (this.value == null || this.value === '') && !this._isNeverEmpty(); }
122122

123123
focused = false;
124124

0 commit comments

Comments
 (0)