> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Input

A single-line text field with an optional label, helper text and error message.


## Installation

```bash
npx @blotch/dolan add input
```

```typescript
import { UiInput } from '../components/ui/input';
```

## Usage

```typescript title="src/app/app.ts"
import { Component, signal } from '@angular/core';
import { UiInput } from '../components/ui/input';

@Component({
  selector: 'app-root',
  imports: [UiInput],
  template: `
    <ui-input label="Email" placeholder="you@example.com" [(value)]="email" />
  `,
})
export class App {
  protected readonly email = signal('');
}
```

- `[(value)]` updates your signal on every keystroke. Setting the signal from code updates the field too.
- The field shows a focus ring while it has focus.
- `class` styles the whole block of label, field and message, so use it for spacing such as `class="mt-4"`.

### Helper text and errors

```angular-html
<ui-input
  label="Username"
  helperText="At least 3 characters"
  [(value)]="username"
/>
<ui-input
  label="Password"
  type="password"
  [error]="passwordError()"
  [(value)]="password"
/>
```

- `helperText` shows small muted text under the field.
- A non-empty `error` replaces the helper text with red text and turns the ring red. The field shakes when an error first appears.

### Types

```angular-html
<ui-input label="Password" type="password" [(value)]="password" />
```

`type` goes to the underlying [`<input>`](/api/elements/input.md) element, which takes `text`, `number` and `password`.

### Disabled

```angular-html
<ui-input label="Account ID" value="ACC-12345" disabled />
```

A disabled field dims and ignores typing.

### Signal Forms

`UiInput` implements Angular's `FormValueControl`, so it works with the `[formField]` directive of Signal Forms (see [Forms](/guide/forms.md)).

- **It emits `touch` when the field loses focus,** as a native `<input>` does. So the field counts as touched, and an error can show as soon as the user leaves the field.
- **A form's `maxLength()` and `readonly()` reach the field.**
- **`focusBoundControl()`** focuses it and opens the keyboard.
- **For a number field, use `<input type="number">`** (see [Numbers](/guide/forms.md#numbers)). `UiInput` holds a string.

```typescript title="src/app/app.ts"
import { Component, computed, signal } from '@angular/core';
import { form, FormField, required } from '@angular/forms/signals';
import { UiInput } from '../components/ui/input';

@Component({
  selector: 'app-root',
  imports: [FormField, UiInput],
  template: `
    <ui-input label="Name" [formField]="profile.name" [error]="nameError()" />
  `,
})
export class App {
  readonly #model = signal({ name: '' });

  protected readonly profile = form(this.#model, (s) => {
    required(s.name, { message: 'Enter your name' });
  });

  protected readonly nameError = computed(() => {
    const name = this.profile.name();
    return name.touched() ? (name.errors()[0]?.message ?? '') : '';
  });
}
```

## API

### UiInput

| Input                 | Type      | Default  | Description                                                                   |
| --------------------- | --------- | -------- | ----------------------------------------------------------------------------- |
| `value`               | `string`  | `''`     | The text. Supports `[(value)]`.                                               |
| `label`               | `string`  | `''`     | Text above the field. Hidden when empty.                                      |
| `accessibility-label` | `string`  | `''`     | The field's name for screen readers when it has no `label`.                   |
| `placeholder`         | `string`  | `''`     | Hint shown while the field is empty.                                          |
| `type`                | `string`  | `'text'` | The `<input>` element's type, such as `password`.                             |
| `helperText`          | `string`  | `''`     | Muted text under the field. Hidden while `error` is set.                      |
| `error`               | `string`  | `''`     | Error text. Turns the ring red and shakes the field.                          |
| `disabled`            | `boolean` | `false`  | Dims the field and ignores typing.                                            |
| `class`               | `string`  | `''`     | Extra Tailwind classes for the outer block.                                   |
| `maxLength`           | `number`  | —        | The most characters the field takes. Signal Forms sets it from `maxLength()`. |
| `readonly`            | `boolean` | `false`  | The text can't be changed. Signal Forms sets it from `readonly()`.            |

| Output        | Type     | Description                                         |
| ------------- | -------- | --------------------------------------------------- |
| `valueChange` | `string` | Emits the text on every keystroke, for `[(value)]`. |
| `changed`     | `string` | Emits the text on every keystroke.                  |
| `focused`     | `void`   | Emits when the field gains focus.                   |
| `blurred`     | `void`   | Emits when the field loses focus.                   |
| `touch`       | `void`   | Emits when the field loses focus, for forms.        |

## Accessibility

- **A screen reader reads the field with its `label`,** which becomes the native `<input>`'s `accessibility-label`, and then the text in it. The label above the field isn't a stop of its own, so it isn't read twice.
- **A field without a `label` takes its name from `accessibility-label`,** for a field under a label of your own, such as one of several fields under one heading. Without either, a screen reader reads only the placeholder. `label` wins when both are set.
- **Tests find it by its label too:** `getByRole('textbox', { name: 'Email' })` returns the `<input>`. A password field has no ARIA role, so find it with `getByAccessibilityLabel('Password')`.

## Related

- [Textarea](/dolan/textarea.md): a multi-line field
- [Label](/dolan/label.md): a caption for other controls
- [Forms](/guide/forms.md): forms and the on-screen keyboard
- [`<input>`](/api/elements/input.md): the element underneath
