Skip to content
GitHub (opens in a new tab)

Field

One labeled control with optional hint and an error or success message. Label on top or start (left).

stableMoleculecontracts/field.json

Preview

Field

Label, control, hint, and error as one piece. FieldSet is the form group. No FieldLabel, Form, or FormDisplay.

Master

A payment form from kit Card, Field, FieldSet, Input, Select, Textarea, and Checkbox.

Payment method

Card details for this workspace

16 digits on the front of the card

Billing address

Where the card is billed

Usage

Use Field for a labeled control. Use FieldSet when a legend wraps related fields. settings-form is the page pattern.

Compose

Field wraps one control. FieldSet is the legend group. Card is the chrome. Do not add Form or FieldLabel.

Do's

  • Any labeled Input, Textarea, Select, DatePicker, or Switch
  • When helper text or a validation error sits with the control

Don'ts

  • Checkbox with its own label and no extra hint/error — use Checkbox
  • RadioGroup — it provides its own legend
  • A group of fields with a legend — use FieldSet
  • Display-only content — use Section
  • Required instructions stay in hint — help is extra explanation, not a substitute
<Card
  title="Payment method"
  description="Card details for this workspace"
  actions={[{ label: "Pay $49.00", appearance: "solid", mode: "primary" }, { label: "Cancel", appearance: "outline", mode: "neutral" }]}
>
  <Field label="Name on card" htmlFor="name">
    <Input id="name" placeholder="Priya Shah" />
  </Field>
  <Field label="Card number" htmlFor="card" hint="16 digits on the front of the card">
    <Input id="card" placeholder="4242 4242 4242 4242" iconStart="CreditCard" />
  </Field>
  <FieldSet legend="Billing address" description="Where the card is billed">
    <Checkbox id="same" label="Same as shipping address" />
  </FieldSet>
</Card>

When to use

  • Any labeled Input, Textarea, Select, DatePicker, or Switch
  • When helper text or a validation error sits with the control

When not to use

  • Checkbox with its own label and no extra hint/error — use Checkbox
  • RadioGroup — it provides its own legend
  • A group of fields with a legend — use FieldSet
  • Display-only content — use Section
  • Required instructions stay in hint — help is extra explanation, not a substitute

What an agent reads

import { Field } from "agentic-ds-kit";
must
  • No role on the wrapper (a nameless group added nothing); the label has id {htmlFor}-label
  • Label htmlFor matches child control id
  • Hint id, then the error or success id, is passed to the child as describedBy
  • Spacing: 8px from label to control, 4px from control to hint and from hint to message
  • required sets aria-required on controls that take it; there is no asterisk
  • A Slider child gets labelledBy={htmlFor}-label, since a label for cannot name role=slider
  • When help is set, HelpPopover sits beside the label; hint and message stay under the control
  • data-invalid when error is set, data-success when success is set and error is not
  • The message icon is aria-hidden; the words carry the state
  • changed adds Edited outside the label with id {htmlFor}-changed, first in describedBy; its Pencil is aria-hidden
defaults
  • helpLabel Help
  • optional false
  • required false
  • changed false
  • labelPosition top
stops if
  • Do not invent FieldLabel, FieldContent, FieldDescription, FieldError, FieldTitle, FieldGroup, FieldLegend, FieldSeparator, Form, FormField, FormItem, FormControl, or FormMessage
  • Do not wrap Button or layout components
  • Do not use start on Field for prefix text — that is Input start
  • Do not put help on Input, Textarea, Select, or DatePicker — Field owns it
  • Do not add an asterisk for required — set required, and mark the rarer kind with optional
  • Do not build an error summary component — on submit, show an Alert (tone danger) with one Button per field that moves focus to it, and focus the Alert
  • Do not add a previous-value prop or a Badge for changed fields — set changed and put the old value in hint
  • Do not use raw hex

From contracts/field.json: must is the a11y requirements, defaults the prop defaults, stops if the doNot rules where the agent asks instead of inventing a cousin.

Props

NameTypeRequiredDefaultNotes
labelstringYes——
htmlForstringYes——
hintstringNo—Helper text, 12/16 muted, 4px under the control. Stays when error or success shows; the message goes under it.
helpstringNo—Extra explanation. Field puts HelpPopover beside the label (placement right). title is the Field label. content is help. Not a substitute for hint.
helpLabelstringNoHelpName of the help button shown with help. Set it to translate.
errorstringNo—Says what to do (Enter a postcode with 5 digits), not Invalid input. CircleX 16px icon plus text.danger words. No role=alert: an Alert error summary announces errors on submit. Wins over success.
successstringNo—Confirmation under the hint, e.g. Email verified. CircleCheck 16px icon plus text.success words, never colour alone. Hidden while error is set.
optionalbooleanNofalseAdds the muted word Optional (KitLabels optional) after the label. Mark the rarer kind: when most fields are required, the optional ones say Optional. Ignored when required is set.
requiredbooleanNofalseSets aria-required on the control when its named element takes it (Input, Textarea, Checkbox, Switch, ColorPicker). No asterisk. Button triggers (Select, the date pickers) are left alone.
changedbooleanNofalseThe value differs from the last save. Adds the word Edited (KitLabels edited), 12/16 text.brand with a 12px Pencil, beside the label and outside it, so the label stays the control's name. Its id ({htmlFor}-changed) leads describedBy. Put the old value in hint (Was "Northwind Traders Ltd"). Pair with SaveBar, which lists the changed fields.
labelPositiontop | startNotoptop stacks. start is horizontal (label left). Hint and error stay under the control.
childrenslotYes——
  • Component
    →

    Checkbox

    Multi-select or confirmation control.

  • Component
    →

    RadioGroup

    Choose exactly one option from a small visible set.

  • Component
    →

    FieldSet

    Semantic group of fields with a legend and optional description.

  • Component
    →

    Section

    Grouped page block with optional heading, description, and actions.