Input
A single-line text field with an optional label, helper text and error message.
Installation
Usage
src/app/app.ts
[(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.
classstyles the whole block of label, field and message, so use it for spacing such asclass="mt-4".
Helper text and errors
helperTextshows small muted text under the field.- A non-empty
errorreplaces the helper text with red text and turns the ring red. The field shakes when an error first appears.
Types
type goes to the underlying <input> element, which takes text, number and password.
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).
- It emits
touchwhen 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()andreadonly()reach the field. focusBoundControl()focuses it and opens the keyboard.- For a number field, use
<input type="number">(see Numbers).UiInputholds a string.
src/app/app.ts
API
UiInput
Accessibility
- A screen reader reads the field with its
label, which becomes the native<input>'saccessibility-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
labeltakes its name fromaccessibility-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.labelwins 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 withgetByAccessibilityLabel('Password').
