MCPcopy Create free account
hub / github.com/angular/components / _updateFocusState

Method _updateFocusState

src/material/form-field/form-field.ts:563–581  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

561 }
562
563 private _updateFocusState() {
564 const controlFocused = this._unwrapMaybeSignal(this._control.focused);
565
566 // Usually the MDC foundation would call "activateFocus" and "deactivateFocus" whenever
567 // certain DOM events are emitted. This is not possible in our implementation of the
568 // form field because we support abstract form field controls which are not necessarily
569 // of type input, nor do we have a reference to a native form field control element. Instead
570 // we handle the focus by checking if the abstract form field control focused state changes.
571 if (controlFocused && !this._isFocused) {
572 this._isFocused = true;
573 this._lineRipple?.activate();
574 } else if (!controlFocused && (this._isFocused || this._isFocused === null)) {
575 this._isFocused = false;
576 this._lineRipple?.deactivate();
577 }
578
579 this._elementRef.nativeElement.classList.toggle('mat-focused', controlFocused);
580 this._textField?.nativeElement.classList.toggle('mdc-text-field--focused', controlFocused);
581 }
582
583 /**
584 * The floating label in the docked state needs to account for prefixes. The horizontal offset

Callers 2

ngAfterViewInitMethod · 0.95
_initializeControlMethod · 0.95

Calls 4

_unwrapMaybeSignalMethod · 0.95
activateMethod · 0.65
toggleMethod · 0.65
deactivateMethod · 0.45

Tested by

no test coverage detected