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