@@ -43,15 +43,14 @@ export class MatFormFieldNotchedOutline implements AfterViewInit {
43
43
/** Whether the notch should be opened. */
44
44
@Input ( 'matFormFieldNotchedOutlineOpen' ) open : boolean = false ;
45
45
46
- @ViewChild ( 'notch' ) _notch : ElementRef ;
47
-
48
- constructor ( ...args : unknown [ ] ) ;
49
- constructor ( ) { }
46
+ @ViewChild ( 'notch' ) _notch : ElementRef < HTMLElement > ;
50
47
51
48
ngAfterViewInit ( ) : void {
52
- const label = this . _elementRef . nativeElement . querySelector < HTMLElement > ( '.mdc-floating-label' ) ;
49
+ const element = this . _elementRef . nativeElement ;
50
+ const label = element . querySelector < HTMLElement > ( '.mdc-floating-label' ) ;
51
+
53
52
if ( label ) {
54
- this . _elementRef . nativeElement . classList . add ( 'mdc-notched-outline--upgraded' ) ;
53
+ element . classList . add ( 'mdc-notched-outline--upgraded' ) ;
55
54
56
55
if ( typeof requestAnimationFrame === 'function' ) {
57
56
label . style . transitionDuration = '0s' ;
@@ -60,19 +59,29 @@ export class MatFormFieldNotchedOutline implements AfterViewInit {
60
59
} ) ;
61
60
}
62
61
} else {
63
- this . _elementRef . nativeElement . classList . add ( 'mdc-notched-outline--no-label' ) ;
62
+ element . classList . add ( 'mdc-notched-outline--no-label' ) ;
64
63
}
65
64
}
66
65
67
66
_setNotchWidth ( labelWidth : number ) {
67
+ const notch = this . _notch . nativeElement ;
68
+
68
69
if ( ! this . open || ! labelWidth ) {
69
- this . _notch . nativeElement . style . width = '' ;
70
+ notch . style . width = '' ;
70
71
} else {
71
72
const NOTCH_ELEMENT_PADDING = 8 ;
72
73
const NOTCH_ELEMENT_BORDER = 1 ;
73
- this . _notch . nativeElement . style . width = `calc(${ labelWidth } px * var(--mat-mdc-form-field-floating-label-scale, 0.75) + ${
74
+ notch . style . width = `calc(${ labelWidth } px * var(--mat-mdc-form-field-floating-label-scale, 0.75) + ${
74
75
NOTCH_ELEMENT_PADDING + NOTCH_ELEMENT_BORDER
75
76
} px)`;
76
77
}
77
78
}
79
+
80
+ _setMaxWidth ( prefixAndSuffixWidth : number ) {
81
+ // Set this only on the notch to avoid style recalculations in other parts of the form field.
82
+ this . _notch . nativeElement . style . setProperty (
83
+ '--mat-form-field-notch-max-width' ,
84
+ `calc(100% - ${ prefixAndSuffixWidth } px)` ,
85
+ ) ;
86
+ }
78
87
}
0 commit comments