Skip to content

Commit 52aa715

Browse files
mmalerbatinayuangao
authored andcommitted
fix(input): fix placeholder for number input with bad input. (#2362)
* fix(input): fix placeholder for number input with bad input. * addressed comments * add comment
1 parent 080f570 commit 52aa715

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/lib/input/input-container.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,14 @@ 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+
return !this._isNeverEmpty() &&
157+
(this.value == null || this.value === '') &&
158+
// Check if the input contains bad input. If so, we know that it only appears empty because
159+
// the value failed to parse. From the user's perspective it is not empty.
160+
// TODO(mmalerba): Add e2e test for bad input case.
161+
!this._isBadInput();
162+
}
156163

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

@@ -199,6 +206,10 @@ export class MdInputDirective {
199206

200207
private _isNeverEmpty() { return this._neverEmptyInputTypes.indexOf(this._type) !== -1; }
201208

209+
private _isBadInput() {
210+
return (this._elementRef.nativeElement as HTMLInputElement).validity.badInput;
211+
}
212+
202213
/** Determines if the component host is a textarea. If not recognizable it returns false. */
203214
private _isTextarea() {
204215
let nativeElement = this._elementRef.nativeElement;

0 commit comments

Comments
 (0)