Chapter 04 Fields
Text field
Label, input, hint and error as one control. The label, hint and error are tied to the input, so screen readers read all three.
import { TextFieldComponent } from '@okaapi-ui/angular';
// Works with formControlName, [formControl] and ngModel.Works with
With a hint
We only use it for order updates.
<ui-text-field
label="Email"
type="email"
hint="We only use it for order updates."
autocomplete="email"
formControlName="email"
/>With an error
Pass the translated message. The input gets aria-invalid, a thicker border, and the message is announced. Colour is never the only sign.
Enter your full name
<ui-text-field
label="Full name"
formControlName="name"
[error]="form.controls.name.invalid ? 'Enter your full name' : undefined"
/>Disabled
Disable it through the form control, as with any input.
order = new FormControl({ value: 'ORD-1042', disabled: true });
<ui-text-field label="Order number" [formControl]="order" />In Arabic
بنستخدمه لتحديثات الطلب بس.
<!-- dir="rtl" on the page or any ancestor -->
<ui-text-field label="البريد الإلكتروني" type="email" hint="بنستخدمه لتحديثات الطلب بس." />When to use something else
| If you need | Use |
|---|---|
| Several lines of text | Textarea |
| A unit or currency beside the value | Input group |
| A number with − and + buttons | Number field |
| Search with a clear button | Search field |
Inputs
| Name | Type | Default | What it does |
|---|---|---|---|
label | string | — | Required. The visible label, tied to the input. |
type | 'text' | 'email' | 'password' | 'search' | 'tel' | 'url' | 'text' | The input type. |
hint | string | — | Help text under the input, read with it. |
error | string | — | The translated error. Marks the input invalid and announces the message. |
autocomplete | string | — | The browser autofill hint, such as email or name. |
testId | string | — | data-testid on the input, for tests. |
Keyboard and screen readers
- The label, hint and error are tied to the input, so all three are read.
- An error is announced when it appears.