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(form-field): make outline appearance work in situations where the… #10943

Merged
merged 2 commits into from
Apr 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/demo-app/input/input-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -647,3 +647,23 @@ <h3>&lt;textarea&gt; with ngModel</h3>
</form>
</mat-card-content>
</mat-card>

<mat-card class="demo-card demo-basic">
<mat-toolbar color="primary">Outline form field in a tab</mat-toolbar>
<mat-card-content>
<mat-tab-group>
<mat-tab label="Tab 1">
<mat-form-field appearance="outline">
<mat-label>Tab 1 input</mat-label>
<input matInput value="test">
</mat-form-field>
</mat-tab>
<mat-tab label="Tab 2">
<mat-form-field appearance="outline">
<mat-label>Tab 2 input</mat-label>
<input matInput value="test">
</mat-form-field>
</mat-tab>
</mat-tab-group>
</mat-card-content>
</mat-card>
14 changes: 9 additions & 5 deletions src/lib/form-field/form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ export class MatFormField extends _MatFormFieldMixinBase

_outlineGapStart = 0;

_initialGapCalculated = false;
Copy link
Member

Choose a reason for hiding this comment

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

Rather than adding another property, couldn't we get away with checking that the gap is greater than 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently that would cause a check loop for other types of form-field, since they set the gap to 0. I could set it to 1 or some other number in that case since its not really used, but this just seemed clearer


/**
* @deprecated
* @deletion-target 7.0.0
Expand Down Expand Up @@ -265,15 +267,13 @@ export class MatFormField extends _MatFormFieldMixinBase
this._syncDescribedByIds();
this._changeDetectorRef.markForCheck();
});

Promise.resolve().then(() => {
this.updateOutlineGap();
this._changeDetectorRef.markForCheck();
});
}

ngAfterContentChecked() {
this._validateControlChild();
if (!this._initialGapCalculated) {
Promise.resolve().then(() => this.updateOutlineGap());
}
}

ngAfterViewInit() {
Expand Down Expand Up @@ -419,6 +419,9 @@ export class MatFormField extends _MatFormFieldMixinBase
// getBoundingClientRect isn't available on the server.
return;
}
if (!document.contains(this._elementRef.nativeElement)) {
Copy link
Member

Choose a reason for hiding this comment

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

This one'll probably throw in Universal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The line above is returning if we're not in the browser

return;
}

const containerStart = this._getStartEnd(
this._connectionContainerRef.nativeElement.getBoundingClientRect());
Expand All @@ -434,6 +437,7 @@ export class MatFormField extends _MatFormFieldMixinBase
this._outlineGapStart = 0;
this._outlineGapWidth = 0;
}
this._initialGapCalculated = true;
this._changeDetectorRef.markForCheck();
}

Expand Down