Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(input): fix placeholder for number input with bad input. #2362

Merged
merged 3 commits into from
Jan 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/lib/input/input-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,14 @@ export class MdInputDirective {
*/
@Output() _placeholderChange = new EventEmitter<string>();

get empty() { return (this.value == null || this.value === '') && !this._isNeverEmpty(); }
get empty() {
return !this._isNeverEmpty() &&
(this.value == null || this.value === '') &&
// Check if the input contains bad input. If so, we know that it only appears empty because
// the value failed to parse. From the user's perspective it is not empty.
// TODO(mmalerba): Add e2e test for bad input case.
!this._isBadInput();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit complex with four different return statements. How about:

return !this._isNeverEmpty() &&
  (this.value == null || this.value === '') &&
  !this._isBadInput();


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

Expand Down Expand Up @@ -199,6 +206,10 @@ export class MdInputDirective {

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

private _isBadInput() {
return (this._elementRef.nativeElement as HTMLInputElement).validity.badInput;
}

/** Determines if the component host is a textarea. If not recognizable it returns false. */
private _isTextarea() {
let nativeElement = this._elementRef.nativeElement;
Expand Down