Forms
FormItem
Field wrapper with label, helper or error text, required marker and optional remove action.
import { FormItem, FormItemTop, FormItemTopLabel, FormItemTopAside } from "datui";Playground
<FormItem top="Name" bottom="Helper text" status="default" />Examples
Label, hint and error
datui controls inside are wired to the label and bottom text automatically.
Custom header
Compose FormItemTop with a label and an aside such as a counter.
Accessibility
- A text
toprenders a<label>pointing at the control id (generated, orhtmlFor). bottomis linked througharia-describedby; withstatus="error"it getsrole="alert"and the control getsaria-invalid.requiredsetsrequiredon the control; the*marker isaria-hidden.- Custom controls can join the wiring through
useFormItemControl().
API
FormItem
Field wrapper: label (`top`), control (`children`), helper/error text (`bottom`). datui text controls inside (Input, Textarea, Search, NativeSelect, Select, SelectMimicry) are wired automatically: id ↔ label, `aria-describedby` ↔ bottom, `aria-invalid` from `status`, `required`. Custom controls call `useFormItemControl()`.
| Prop | Type | Default | Description |
|---|---|---|---|
| bottom | ReactNode | — | Helper or error text under the control, linked through `aria-describedby`. |
| bottomId | string | — | Id of the bottom text. |
| className | string | — | |
| htmlFor | string | — | Id of the control. Defaults to a generated id that datui controls inside pick up automatically. |
| noPadding | boolean | false | Removes the horizontal padding. |
| onRemove | ((event: MouseEvent<HTMLButtonElement, MouseEvent>) => void) | — | |
| removable | boolean | "indent" | — | `true` shows a remove button after the content; `"indent"` only reserves its space for alignment. |
| removeLabel | string | — | Accessible label of the remove button. |
| required | boolean | false | Marks the label with `*` and sets `required` on the control. |
| status | FormFieldStatus | default | Validation state passed to the control (border + `aria-invalid`) and bottom text color. |
| top | ReactNode | — | Label. A string/number renders a `<label>` for the control; pass a `FormItemTop` for custom headers. |
| topId | string | — | Id of the label element. |
| topMultiline | boolean | false | Let a text `top` wrap instead of truncating. |
FormItemTop
Header row of a FormItem: a `FormItemTopLabel` plus optional `FormItemTopAside`.
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | — |
FormItemTopLabel
Field label. Renders `<label>` when it has a control to point at, otherwise `<span>`.
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | — | |
| htmlFor | string | — | Id of the labelled control. Inside a FormItem it defaults to the item's control id. |
| multiline | boolean | false | Allow wrapping instead of truncating. |
| required | boolean | — | Show the required marker. Inside a FormItem it defaults to the item's `required`. |
FormItemTopAside
End-aligned secondary header content, e.g. a character counter (give dynamic counters `aria-live="polite"`).
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | — |