|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -import {Direction, Directionality} from '@angular/cdk/bidi'; |
| 9 | +import {Directionality} from '@angular/cdk/bidi'; |
10 | 10 | import {coerceBooleanProperty} from '@angular/cdk/coercion';
|
11 | 11 | import {
|
12 | 12 | AfterContentChecked,
|
@@ -231,15 +231,6 @@ export class MatFormField extends _MatFormFieldMixinBase
|
231 | 231 | /** Whether the Angular animations are enabled. */
|
232 | 232 | _animationsEnabled: boolean;
|
233 | 233 |
|
234 |
| - /* Holds the previous direction emitted by directionality service change emitter. |
235 |
| - This is used in updateOutlineGap() method to update the width and position of the gap in the |
236 |
| - outline. Only relevant for the outline appearance. The direction is getting updated in the |
237 |
| - UI after directionality service change emission. So the outlines gaps are getting |
238 |
| - updated in updateOutlineGap() method before connectionContainer child direction change |
239 |
| - in UI. We may get wrong calculations. So we are storing the previous direction to get the |
240 |
| - correct outline calculations*/ |
241 |
| - private _previousDirection: Direction = 'ltr'; |
242 |
| - |
243 | 234 | /**
|
244 | 235 | * @deprecated
|
245 | 236 | * @breaking-change 8.0.0
|
@@ -355,8 +346,13 @@ export class MatFormField extends _MatFormFieldMixinBase
|
355 | 346 |
|
356 | 347 | if (this._dir) {
|
357 | 348 | this._dir.change.pipe(takeUntil(this._destroyed)).subscribe(() => {
|
358 |
| - this.updateOutlineGap(); |
359 |
| - this._previousDirection = this._dir.value; |
| 349 | + if (typeof requestAnimationFrame === 'function') { |
| 350 | + this._ngZone.runOutsideAngular(() => { |
| 351 | + requestAnimationFrame(() => this.updateOutlineGap()); |
| 352 | + }); |
| 353 | + } else { |
| 354 | + this.updateOutlineGap(); |
| 355 | + } |
360 | 356 | });
|
361 | 357 | }
|
362 | 358 | }
|
@@ -579,7 +575,7 @@ export class MatFormField extends _MatFormFieldMixinBase
|
579 | 575 |
|
580 | 576 | /** Gets the start end of the rect considering the current directionality. */
|
581 | 577 | private _getStartEnd(rect: ClientRect): number {
|
582 |
| - return this._previousDirection === 'rtl' ? rect.right : rect.left; |
| 578 | + return (this._dir && this._dir.value === 'rtl') ? rect.right : rect.left; |
583 | 579 | }
|
584 | 580 |
|
585 | 581 | /** Checks whether the form field is attached to the DOM. */
|
|
0 commit comments