Field
Label, hint, validation message, required state, and ARIA wiring around one form control.
Preview
A live, theme-aware example rendered with the published component.
Loading preview…
Import
Import from the focused entry point below, or use the same named export from @tavojs/ui. Both are public APIs; measure the built application when comparing their bundle cost.
tsximport { Field } from "@tavojs/ui/field";The component import loads compiled component CSS. Enable tavoUi() for your project theme variables, or import @tavojs/ui/theme.css once for the package default theme. The equivalent CSS-safe component alias is @tavojs/ui/css/field.
When to use
Use it when
Choose something else when
Examples
These examples include imports and local state where interaction requires it. Render the exported component in a page after completing UI installation. Demo state stays in the mounted component; connect file handling, persistence, and data loading to your application as needed.
Labeled text input
tsximport { Field } from "@tavojs/ui/field";
import { TextInput } from "@tavojs/ui";
export function FieldExample1() {
return (
<>
<Field id="account-email" label="Email" hint="Used for account notices" required>
<TextInput name="email" type="email" required />
</Field>
</>
);
}Common props and defaults
A curated starting point. The complete TypeScript API below includes additional props and compound member contracts.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Optional class hook applied to the public root element owned by the component. |
label | Child | Required | Visible field label. |
hint | Child | — | Configures hint for this component. |
error | Child | — | Validation message and invalid state. |
success | Child | — | Configures success for this component. |
warning | Child | — | Configures warning for this component. |
required | boolean | false | Marks the field as required. |
optional | boolean | — | Configures optional for this component. |
id | string | — | Configures id for this component. |
description | Child | — | Helper text announced with the control. |
Complete TypeScript API
Import from @tavojs/ui/field. Published exports: Field, FieldProps, FieldRoot, Fieldset, FieldsetProps, FormMessage, FormMessageProps, Legend.
FieldProps
| Property | Type | Required | Description |
|---|---|---|---|
label | Child | Yes | Visible field label. |
hint | Child | No | Configures hint for this component. |
error | Child | No | Validation message and invalid state. |
success | Child | No | Configures success for this component. |
warning | Child | No | Configures warning for this component. |
required | boolean | No | Marks the field as required. |
optional | boolean | No | Configures optional for this component. |
id | string | No | Configures id for this component. |
className | string | No | Optional class hook applied to the public root element owned by the component. |
children | Child | No | Inherited children attribute accepted by Field. |
FormMessageProps
| Property | Type | Required | Description |
|---|---|---|---|
children | Child | No | Inherited children attribute accepted by Field. |
tone | "success" | "warning" | "danger" | "neutral" | No | Inherited tone attribute accepted by Field. |
id | string | No | Configures id for this component. |
className | string | No | Optional class hook applied to the public root element owned by the component. |
FieldsetProps
| Property | Type | Required | Description |
|---|---|---|---|
legend | Child | No | Inherited legend attribute accepted by Field. |
hint | Child | No | Configures hint for this component. |
className | string | No | Optional class hook applied to the public root element owned by the component. |
children | Child | No | Inherited children attribute accepted by Field. |
State ownership and DOM target
| Concern | Contract |
|---|---|
| State | No component state contract is exposed; the application owns the rendered content and surrounding behavior. |
| DOM target | Native input attributes target the owned form control; wrapper-specific props stay on the documented component root. |
Anatomy and related components
Limitations
Field is not the input itself and is not a form submission boundary. Use TextInput for the native control and FormControl for the enclosing form.
Use only the documented props, entry points, and compound members. Internal DOM nesting and CSS class names can change without becoming part of the public component contract.
Accessibility
Adds id, aria-describedby, and aria-invalid to child controls.
Adds id, aria-describedby, and aria-invalid to child controls.
Component status
| Contract | Current value |
|---|---|
| Maturity | stable |
| Category | forms |
| Component import | @tavojs/ui/field |
| Explicit CSS import | @tavojs/ui/css/field |
| Preview | Interactive preview available on this page |