Skip to content

Commit

Permalink
fix(input): treat number 0 as non-empty (#2245)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalerba authored and jelbourn committed Dec 16, 2016
1 parent 34642ea commit a818579
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/lib/input/input-container.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('MdInputContainer', function () {
MdInputContainerTextTestController,
MdInputContainerPasswordTestController,
MdInputContainerNumberTestController,
MdInputContainerZeroTestController,
MdTextareaWithBindings,
MdInputContainerWithDisabled,
MdInputContainerMissingMdInputTestController
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/input/input-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit a818579

Please sign in to comment.