A compound wrapper for labelled form fields with helper and error text.
import { Field } from '@oztix/roadie-components/field'
Use showIndicator on Field.Label to automatically render a required or
optional indicator based on the Field's required prop. This eliminates the
need to manually import and place RequiredIndicator or OptionalIndicator.
Fields inherit input interaction states. Focus shows accent colouring,
invalid shows danger colouring with error text. The invalid and disabled
props flow through context to child inputs automatically.
Field exposes sub-components for label, input, textarea, helper text, and error text.
Set invalid on the Field root to activate the danger state. The input
border and focus ring automatically switch to danger colours, and
aria-invalid is set on the input automatically.
Controls that read typed text, such as DateField, also show their own error in Field.ErrorText when the text names nothing, such as "Enter a date, like 14 Mar or next Fri". It shows even when invalid isn't set, and wins over the error text's children until the text is fixed.
Write labels, helper text, and error text with Interface copy.
htmlFor or id manually.invalid, required, and disabled props on Field automatically set aria-invalid, aria-required, and disabled on child inputs via context.Field.ErrorText renders with role="alert" and only appears when invalid is true or a control reports its own error, so screen readers announce errors immediately.aria-describedby is automatically wired to the helper text (or error text when invalid).Reads the nearest Field's state. Use it when building a custom control that
needs to react to the same invalid / required / disabled state as
Field.Input, without reimplementing Field's own sub-components. Outside a
Field, every value comes back empty or undefined.
| Field | Type | Description |
|---|---|---|
invalid | boolean | undefined | Whether the field is invalid. |
required | boolean | undefined | Whether the field is required. |
disabled | boolean | undefined | Whether the field is disabled. |
fieldId | string | The id wired to the input and its label. |
labelId | string | The label's id. |
helperTextId | string | Field.HelperText's id. |
errorTextId | string | Field.ErrorText's id. |
Derives the DOM attributes a custom input needs from the nearest Field's
context: this is what Field.Input and Field.Textarea spread onto their own
element. Reach for it when building a control Field.Input doesn't cover.
| Field | Type | Description |
|---|---|---|
id | string | undefined | Matches Field.Label's htmlFor. |
disabled | boolean | undefined | The field's disabled state. |
aria-invalid | boolean | undefined | The field's invalid state. |
aria-required | boolean | undefined | The field's required state. |
aria-describedby | string | undefined | The error text's id when invalid, otherwise the helper text's id. |
function useFieldControlError(message: string | null): void
Shows a control's own error in Field.ErrorText while the control is
mounted, such as a date it can't read or a file it couldn't upload. Pass
null once the problem is fixed. The control's message wins over the
error text's children, and shows even when the field isn't invalid. With
several controls in one field, the first to mount shows its error first.
Outside a Field it does nothing. It returns nothing.
It doesn't mark the control itself, and useFieldInputProps follows only the
field's invalid. While the control has an error, set aria-invalid on it
and point its aria-describedby at errorTextId from useFieldContext, as
Roadie's date and time fields do.
Shows when the field is invalid, or when its control can't read what was typed. The control's message, such as a date it can't read, wins over `children`, since it says exactly what to fix.
No additional props. It forwards all standard HTML attributes to the underlying element.
No additional props. It forwards all standard HTML attributes to the underlying element.
Inherited from InputProps
Deprecated: Form controls take their colour from state; `is-interactive-field` handles it. Will be removed in v3.0.0.
Inherited from TextareaProps
Deprecated: Form controls take their colour from state; `is-interactive-field` handles it. Will be removed in v3.0.0.