MCPcopy
hub / github.com/angular/components / _updateFocusState

Method _updateFocusState

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

Source from the content-addressed store, hash-verified

546 }
547
548 private _updateFocusState() {
549 const controlFocused = this._control.focused;
550
551 // Usually the MDC foundation would call "activateFocus" and "deactivateFocus" whenever
552 // certain DOM events are emitted. This is not possible in our implementation of the
553 // form field because we support abstract form field controls which are not necessarily
554 // of type input, nor do we have a reference to a native form field control element. Instead
555 // we handle the focus by checking if the abstract form field control focused state changes.
556 if (controlFocused && !this._isFocused) {
557 this._isFocused = true;
558 this._lineRipple?.activate();
559 } else if (!controlFocused && (this._isFocused || this._isFocused === null)) {
560 this._isFocused = false;
561 this._lineRipple?.deactivate();
562 }
563
564 this._elementRef.nativeElement.classList.toggle('mat-focused', controlFocused);
565 this._textField?.nativeElement.classList.toggle('mdc-text-field--focused', controlFocused);
566 }
567
568 /**
569 * The floating label in the docked state needs to account for prefixes. The horizontal offset

Callers 2

ngAfterViewInitMethod · 0.95
_initializeControlMethod · 0.95

Calls 3

activateMethod · 0.65
toggleMethod · 0.65
deactivateMethod · 0.45

Tested by

no test coverage detected