Skip to content

Commit

Permalink
fix(form-field): make outline appearance work in situations where the… (
Browse files Browse the repository at this point in the history
#10943)

* fix(form-field): make outline appearance work in situations where the form field is not initially in the DOM

* fix ssr
  • Loading branch information
mmalerba committed Apr 21, 2018
1 parent deedebd commit a0c77e2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
20 changes: 20 additions & 0 deletions src/demo-app/input/input-demo.html
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>
15 changes: 10 additions & 5 deletions src/lib/form-field/form-field.ts
Expand Up @@ -195,6 +195,8 @@ export class MatFormField extends _MatFormFieldMixinBase

_outlineGapStart = 0;

_initialGapCalculated = false;

/**
* @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 @@ -417,6 +417,10 @@ export class MatFormField extends _MatFormFieldMixinBase
if (this.appearance === 'outline' && this._label && this._label.nativeElement.children.length) {
if (this._platform && !this._platform.isBrowser) {
// getBoundingClientRect isn't available on the server.
this._initialGapCalculated = true;
return;
}
if (!document.contains(this._elementRef.nativeElement)) {
return;
}

Expand All @@ -434,6 +438,7 @@ export class MatFormField extends _MatFormFieldMixinBase
this._outlineGapStart = 0;
this._outlineGapWidth = 0;
}
this._initialGapCalculated = true;
this._changeDetectorRef.markForCheck();
}

Expand Down

0 comments on commit a0c77e2

Please sign in to comment.