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

Class MatFormField

src/material/form-field/form-field.ts:187–830  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

185 ],
186})
187export class MatFormField
188 implements FloatingLabelParent, AfterContentInit, AfterContentChecked, AfterViewInit, OnDestroy
189{
190 _elementRef = inject(ElementRef);
191 private _changeDetectorRef = inject(ChangeDetectorRef);
192 private _platform = inject(Platform);
193 private _idGenerator = inject(_IdGenerator);
194 private _ngZone = inject(NgZone);
195 private _defaults = inject<MatFormFieldDefaultOptions>(MAT_FORM_FIELD_DEFAULT_OPTIONS, {
196 optional: true,
197 });
198 private _currentDirection!: Direction;
199
200 @ViewChild('textField') _textField!: ElementRef<HTMLElement>;
201 @ViewChild('iconPrefixContainer') _iconPrefixContainer!: ElementRef<HTMLElement>;
202 @ViewChild('textPrefixContainer') _textPrefixContainer!: ElementRef<HTMLElement>;
203 @ViewChild('iconSuffixContainer') _iconSuffixContainer!: ElementRef<HTMLElement>;
204 @ViewChild('textSuffixContainer') _textSuffixContainer!: ElementRef<HTMLElement>;
205 @ViewChild(MatFormFieldFloatingLabel) _floatingLabel: MatFormFieldFloatingLabel | undefined;
206 @ViewChild(MatFormFieldNotchedOutline) _notchedOutline: MatFormFieldNotchedOutline | undefined;
207 @ViewChild(MatFormFieldLineRipple) _lineRipple: MatFormFieldLineRipple | undefined;
208
209 private _iconPrefixContainerSignal = viewChild<ElementRef<HTMLElement>>('iconPrefixContainer');
210 private _textPrefixContainerSignal = viewChild<ElementRef<HTMLElement>>('textPrefixContainer');
211 private _iconSuffixContainerSignal = viewChild<ElementRef<HTMLElement>>('iconSuffixContainer');
212 private _textSuffixContainerSignal = viewChild<ElementRef<HTMLElement>>('textSuffixContainer');
213 private _prefixSuffixContainers = computed(() => {
214 return [
215 this._iconPrefixContainerSignal(),
216 this._textPrefixContainerSignal(),
217 this._iconSuffixContainerSignal(),
218 this._textSuffixContainerSignal(),
219 ]
220 .map(container => container?.nativeElement)
221 .filter(e => e !== undefined);
222 });
223
224 @ContentChild(_MatFormFieldControl) _formFieldControl!: MatFormFieldControl<any>;
225 @ContentChildren(MAT_PREFIX, {descendants: true}) _prefixChildren!: QueryList<MatPrefix>;
226 @ContentChildren(MAT_SUFFIX, {descendants: true}) _suffixChildren!: QueryList<MatSuffix>;
227 @ContentChildren(MAT_ERROR, {descendants: true}) _errorChildren!: QueryList<MatError>;
228 @ContentChildren(MatHint, {descendants: true}) _hintChildren!: QueryList<MatHint>;
229
230 private readonly _labelChild = contentChild(MatLabel);
231
232 /** Whether the required marker should be hidden. */
233 @Input()
234 get hideRequiredMarker(): boolean {
235 return this._hideRequiredMarker;
236 }
237 set hideRequiredMarker(value: BooleanInput) {
238 this._hideRequiredMarker = coerceBooleanProperty(value);
239 }
240 private _hideRequiredMarker = false;
241
242 /**
243 * Theme color of the form field. This API is supported in M2 themes only, it
244 * has no effect in M3 themes. For color customization in M3, see https://material.angular.dev/components/form-field/styling.

Callers

nothing calls this directly

Calls 6

_animationsDisabledFunction · 0.90
computedFunction · 0.85
signalFunction · 0.85
_hasFloatingLabelMethod · 0.80
filterMethod · 0.45
getIdMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…