Skip to content

Commit 1ffd52f

Browse files
committed
fix(form-field): update label gap for outline style
1 parent 1e1751f commit 1ffd52f

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

src/lib/form-field/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ng_module(
1818
deps = [
1919
"//src/lib/core",
2020
"//src/cdk/coercion",
21+
"//src/cdk/observers",
2122
"//src/cdk/platform",
2223
],
2324
tsconfig = "//src/lib:tsconfig-build.json",

src/lib/form-field/form-field-module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import {CommonModule} from '@angular/common';
1010
import {NgModule} from '@angular/core';
11+
import {ObserversModule} from '@angular/cdk/observers';
1112
import {MatError} from './error';
1213
import {MatFormField} from './form-field';
1314
import {MatHint} from './hint';
@@ -27,7 +28,10 @@ import {MatSuffix} from './suffix';
2728
MatPrefix,
2829
MatSuffix,
2930
],
30-
imports: [CommonModule],
31+
imports: [
32+
CommonModule,
33+
ObserversModule,
34+
],
3135
exports: [
3236
MatError,
3337
MatFormField,

src/lib/form-field/form-field.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<!-- We add aria-owns as a workaround for an issue in JAWS & NVDA where the label isn't
2828
read if it comes before the control in the DOM. -->
2929
<label class="mat-form-field-label"
30+
(cdkObserveContent)="updateOutlineGap()"
3031
[id]="_labelId"
3132
[attr.for]="_control.id"
3233
[attr.aria-owns]="_control.id"

src/lib/form-field/form-field.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,12 @@ export class MatFormField extends _MatFormFieldMixinBase
481481
this._outlineGapWidth = 0;
482482
}
483483
this._initialGapCalculated = true;
484-
this._changeDetectorRef.markForCheck();
484+
// @breaking-change 7.0.0 Remove this check and else block once _ngZone is required.
485+
if (this._ngZone) {
486+
this._ngZone.run(() => this._changeDetectorRef.markForCheck());
487+
} else {
488+
this._changeDetectorRef.markForCheck();
489+
}
485490
}
486491

487492
/** Gets the start end of the rect considering the current directionality. */

0 commit comments

Comments
 (0)