Skip to content

Commit 03d694a

Browse files
committed
fix(input): fix placeholder for number input with bad input.
1 parent b49bfce commit 03d694a

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/lib/input/input-container.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,21 @@ export class MdInputDirective {
152152
*/
153153
@Output() _placeholderChange = new EventEmitter<string>();
154154

155-
get empty() { return (this.value == null || this.value === '') && !this._isNeverEmpty(); }
155+
get empty() {
156+
if (this._isNeverEmpty()) {
157+
return false;
158+
}
159+
if (this.value == null || this.value === '') {
160+
// Check if this is an <input> element that contains bad input.
161+
// If so, we know that it only appears empty because the value failed to parse.
162+
if (this._elementRef.nativeElement instanceof HTMLInputElement &&
163+
this._elementRef.nativeElement.validity.badInput) {
164+
return false;
165+
}
166+
return true;
167+
}
168+
return false;
169+
}
156170

157171
private get _uid() { return this._cachedUid = this._cachedUid || `md-input-${nextUniqueId++}`; }
158172

0 commit comments

Comments
 (0)