/*! * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import { afterNextRender, ChangeDetectionStrategy, Component, ElementRef, input, model, viewChild, } from '@angular/core'; import {FormValueControl} from '@angular/forms/signals'; import {IconComponent} from '../icon/icon.component'; @Component({ selector: 'docs-text-field', changeDetection: ChangeDetectionStrategy.OnPush, imports: [IconComponent], templateUrl: './text-field.component.html', styleUrls: ['./text-field.component.scss'], host: { class: 'docs-form-element', }, }) export class TextField implements FormValueControl { readonly input = viewChild.required>('inputRef'); readonly name = input(''); readonly value = model(''); readonly placeholder = input(null); readonly disabled = model(false); readonly hideIcon = input(false); readonly autofocus = input(false); readonly resetLabel = input(null); constructor() { afterNextRender(() => { if (this.autofocus()) { this.focus(); } }); } setValue(value: string): void { if (this.disabled()) { return; } this.value.set(value); } clearTextField() { this.setValue(''); } focus() { this.input().nativeElement.focus(); } }