Navigated to /docs/ui/components/field

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.

TSX
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

Use Field around TextInput, Select, Textarea, or another single control when it needs a visible label and correctly connected supporting or validation text.

Choose something else when

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.

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

TSXCreate: src/components/examples/FieldExample1.tsx
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.

PropTypeDefaultDescription
classNamestring

Optional class hook applied to the public root element owned by the component.
labelChild

Required

Visible field label.
hintChild

Configures hint for this component.
errorChild

Validation message and invalid state.
successChild

Configures success for this component.
warningChild

Configures warning for this component.
requiredboolean

false

Marks the field as required.
optionalboolean

Configures optional for this component.
idstring

Configures id for this component.
descriptionChild

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

PropertyTypeRequiredDescription
labelChild

Yes

Visible field label.

hintChild

No

Configures hint for this component.

errorChild

No

Validation message and invalid state.

successChild

No

Configures success for this component.

warningChild

No

Configures warning for this component.

requiredboolean

No

Marks the field as required.

optionalboolean

No

Configures optional for this component.

idstring

No

Configures id for this component.

classNamestring

No

Optional class hook applied to the public root element owned by the component.

childrenChild

No

Inherited children attribute accepted by Field.

FormMessageProps

PropertyTypeRequiredDescription
childrenChild

No

Inherited children attribute accepted by Field.

tone"success" | "warning" | "danger" | "neutral"

No

Inherited tone attribute accepted by Field.

idstring

No

Configures id for this component.

classNamestring

No

Optional class hook applied to the public root element owned by the component.

FieldsetProps

PropertyTypeRequiredDescription
legendChild

No

Inherited legend attribute accepted by Field.

hintChild

No

Configures hint for this component.

classNamestring

No

Optional class hook applied to the public root element owned by the component.

childrenChild

No

Inherited children attribute accepted by Field.

State ownership and DOM target

ConcernContract
StateNo component state contract is exposed; the application owns the rendered content and surrounding behavior.
DOM targetNative input attributes target the owned form control; wrapper-specific props stay on the documented component root.

Anatomy and related components

Public compound members: Root, Message, Fieldset, Legend

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

ContractCurrent value
Maturitystable
Categoryforms
Component import@tavojs/ui/field
Explicit CSS import@tavojs/ui/css/field
PreviewInteractive preview available on this page