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

Class MatFormField

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

Source from the content-addressed store, hash-verified

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