@@ -43,15 +43,14 @@ export class MatFormFieldNotchedOutline implements AfterViewInit {
4343 /** Whether the notch should be opened. */
4444 @Input ( 'matFormFieldNotchedOutlineOpen' ) open : boolean = false ;
4545
46- @ViewChild ( 'notch' ) _notch : ElementRef ;
47-
48- constructor ( ...args : unknown [ ] ) ;
49- constructor ( ) { }
46+ @ViewChild ( 'notch' ) _notch : ElementRef < HTMLElement > ;
5047
5148 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+
5352 if ( label ) {
54- this . _elementRef . nativeElement . classList . add ( 'mdc-notched-outline--upgraded' ) ;
53+ element . classList . add ( 'mdc-notched-outline--upgraded' ) ;
5554
5655 if ( typeof requestAnimationFrame === 'function' ) {
5756 label . style . transitionDuration = '0s' ;
@@ -60,19 +59,29 @@ export class MatFormFieldNotchedOutline implements AfterViewInit {
6059 } ) ;
6160 }
6261 } else {
63- this . _elementRef . nativeElement . classList . add ( 'mdc-notched-outline--no-label' ) ;
62+ element . classList . add ( 'mdc-notched-outline--no-label' ) ;
6463 }
6564 }
6665
6766 _setNotchWidth ( labelWidth : number ) {
67+ const notch = this . _notch . nativeElement ;
68+
6869 if ( ! this . open || ! labelWidth ) {
69- this . _notch . nativeElement . style . width = '' ;
70+ notch . style . width = '' ;
7071 } else {
7172 const NOTCH_ELEMENT_PADDING = 8 ;
7273 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) + ${
7475 NOTCH_ELEMENT_PADDING + NOTCH_ELEMENT_BORDER
7576 } px)`;
7677 }
7778 }
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+ }
7887}
0 commit comments