@@ -48,6 +48,12 @@ import {MatLabel} from './label';
48
48
import { MatPlaceholder } from './placeholder' ;
49
49
import { MatPrefix } from './prefix' ;
50
50
import { MatSuffix } from './suffix' ;
51
+ import { Directionality } from '@angular/cdk/bidi' ;
52
+
53
+
54
+ let nextUniqueId = 0 ;
55
+ const floatingLabelScale = 0.75 ;
56
+ const outlineGapPadding = 5 ;
51
57
52
58
53
59
// Boilerplate for applying mixins to MatFormField.
@@ -56,10 +62,8 @@ export class MatFormFieldBase {
56
62
constructor ( public _elementRef : ElementRef ) { }
57
63
}
58
64
59
- export const _MatFormFieldMixinBase = mixinColor ( MatFormFieldBase , 'primary' ) ;
60
-
61
65
62
- let nextUniqueId = 0 ;
66
+ export const _MatFormFieldMixinBase = mixinColor ( MatFormFieldBase , 'primary' ) ;
63
67
64
68
65
69
export type MatFormFieldAppearance = 'legacy' | 'standard' | 'fill' | 'outline' ;
@@ -118,7 +122,7 @@ export class MatFormField extends _MatFormFieldMixinBase
118
122
private _labelOptions : LabelOptions ;
119
123
120
124
/** The form-field appearance style. */
121
- @Input ( ) appearance : MatFormFieldAppearance = 'outline ' ;
125
+ @Input ( ) appearance : MatFormFieldAppearance = 'legacy ' ;
122
126
123
127
/**
124
128
* @deprecated Use `color` instead.
@@ -191,6 +195,10 @@ export class MatFormField extends _MatFormFieldMixinBase
191
195
}
192
196
private _floatLabel : FloatLabelType ;
193
197
198
+ _outlineGapWidth = 0 ;
199
+
200
+ _outlineGapStart = 0 ;
201
+
194
202
/** @deletion -target 7.0.0 */
195
203
@ViewChild ( 'underline' ) underlineRef : ElementRef ;
196
204
@@ -208,7 +216,8 @@ export class MatFormField extends _MatFormFieldMixinBase
208
216
constructor (
209
217
public _elementRef : ElementRef ,
210
218
private _changeDetectorRef : ChangeDetectorRef ,
211
- @Optional ( ) @Inject ( MAT_LABEL_GLOBAL_OPTIONS ) labelOptions : LabelOptions ) {
219
+ @Optional ( ) @Inject ( MAT_LABEL_GLOBAL_OPTIONS ) labelOptions : LabelOptions ,
220
+ @Optional ( ) private _dir : Directionality ) {
212
221
super ( _elementRef ) ;
213
222
214
223
this . _labelOptions = labelOptions ? labelOptions : { } ;
@@ -255,6 +264,11 @@ export class MatFormField extends _MatFormFieldMixinBase
255
264
this . _syncDescribedByIds ( ) ;
256
265
this . _changeDetectorRef . markForCheck ( ) ;
257
266
} ) ;
267
+
268
+ Promise . resolve ( ) . then ( ( ) => {
269
+ this . _updateOutlineGap ( ) ;
270
+ this . _changeDetectorRef . detectChanges ( ) ;
271
+ } ) ;
258
272
}
259
273
260
274
ngAfterContentChecked ( ) {
@@ -394,4 +408,32 @@ export class MatFormField extends _MatFormFieldMixinBase
394
408
throw getMatFormFieldMissingControlError ( ) ;
395
409
}
396
410
}
411
+
412
+ /**
413
+ * Updates the width and position of the gap in the outline. Only relevant for the outline
414
+ * appearance.
415
+ */
416
+ private _updateOutlineGap ( ) {
417
+ if ( this . appearance === 'outline' && this . _label && this . _label . nativeElement . children . length ) {
418
+ const containerStart = this . _getStartEnd (
419
+ this . _connectionContainerRef . nativeElement . getBoundingClientRect ( ) ) ;
420
+ const labelStart = this . _getStartEnd (
421
+ this . _label . nativeElement . children [ 0 ] . getBoundingClientRect ( ) ) ;
422
+ let labelWidth = 0 ;
423
+ for ( const child of this . _label . nativeElement . children ) {
424
+ labelWidth += child . offsetWidth ;
425
+ }
426
+ this . _outlineGapStart = labelStart - containerStart - outlineGapPadding ;
427
+ this . _outlineGapWidth = labelWidth * floatingLabelScale + outlineGapPadding * 2 ;
428
+ } else {
429
+ this . _outlineGapStart = 0 ;
430
+ this . _outlineGapWidth = 0 ;
431
+ }
432
+ this . _changeDetectorRef . markForCheck ( ) ;
433
+ }
434
+
435
+ /** Gets the start end of the rect considering the current directionality. */
436
+ private _getStartEnd ( rect : ClientRect ) : number {
437
+ return this . _dir && this . _dir . value === 'rtl' ? rect . right : rect . left ;
438
+ }
397
439
}
0 commit comments