@@ -160,7 +160,6 @@ interface MatFormFieldControl<T> extends _MatFormFieldControl<T> {}
160
160
'[class.mat-form-field-appearance-fill]' : 'appearance == "fill"' ,
161
161
'[class.mat-form-field-appearance-outline]' : 'appearance == "outline"' ,
162
162
'[class.mat-form-field-hide-placeholder]' : '_hasFloatingLabel() && !_shouldLabelFloat()' ,
163
- '[class.mat-focused]' : '_control.focused' ,
164
163
'[class.mat-primary]' : 'color !== "accent" && color !== "warn"' ,
165
164
'[class.mat-accent]' : 'color === "accent"' ,
166
165
'[class.mat-warn]' : 'color === "warn"' ,
@@ -340,6 +339,7 @@ export class MatFormField
340
339
private _stateChanges : Subscription | undefined ;
341
340
private _valueChanges : Subscription | undefined ;
342
341
private _describedByChanges : Subscription | undefined ;
342
+ private _outlineLabelOffsetResizeObserver : ResizeObserver | null = null ;
343
343
protected readonly _animationsDisabled = _animationsDisabled ( ) ;
344
344
345
345
constructor ( ...args : unknown [ ] ) ;
@@ -544,27 +544,25 @@ export class MatFormField
544
544
}
545
545
546
546
private _updateFocusState ( ) {
547
+ const controlFocused = this . _control . focused ;
548
+
547
549
// Usually the MDC foundation would call "activateFocus" and "deactivateFocus" whenever
548
550
// certain DOM events are emitted. This is not possible in our implementation of the
549
551
// form field because we support abstract form field controls which are not necessarily
550
552
// of type input, nor do we have a reference to a native form field control element. Instead
551
553
// we handle the focus by checking if the abstract form field control focused state changes.
552
- if ( this . _control . focused && ! this . _isFocused ) {
554
+ if ( controlFocused && ! this . _isFocused ) {
553
555
this . _isFocused = true ;
554
556
this . _lineRipple ?. activate ( ) ;
555
- } else if ( ! this . _control . focused && ( this . _isFocused || this . _isFocused === null ) ) {
557
+ } else if ( ! controlFocused && ( this . _isFocused || this . _isFocused === null ) ) {
556
558
this . _isFocused = false ;
557
559
this . _lineRipple ?. deactivate ( ) ;
558
560
}
559
561
560
- this . _textField ?. nativeElement . classList . toggle (
561
- 'mdc-text-field--focused' ,
562
- this . _control . focused ,
563
- ) ;
562
+ this . _elementRef . nativeElement . classList . toggle ( 'mat-focused' , controlFocused ) ;
563
+ this . _textField ?. nativeElement . classList . toggle ( 'mdc-text-field--focused' , controlFocused ) ;
564
564
}
565
565
566
- private _outlineLabelOffsetResizeObserver : ResizeObserver | null = null ;
567
-
568
566
/**
569
567
* The floating label in the docked state needs to account for prefixes. The horizontal offset
570
568
* is calculated whenever the appearance changes to `outline`, the prefixes change, or when the
0 commit comments