npx shadcn@4.23.1 add @goop/trail-fieldField
FreeA form row that ties one control to its label, its description and its error line, as a settings row or a stacked form field, for React and Tailwind CSS. Free, MIT.
Field
What an agent sees
- FieldValueThe row's current value, shown before its control (an address before its edit button)
import { Field, FieldValue } from '@/components/ui/goop/field';
import { Card } from '@/components/ui/goop/card';
import { Switch } from '@/components/ui/goop/switch';
import { MultiSelect, MultiSelectItem } from '@/components/ui/goop/multi-select';
<Card variant="outline" asChild>
<ul>
<Field as="li" label="Weekly digest" description="A summary every Monday">
{(control) => <Switch {...control} />}
</Field>
<Field as="li" label="Who takes part" description="Every group the study recruits from" stack="always">
<MultiSelect defaultValue={['Clinic staff']} placeholder="Choose who takes part">
<MultiSelectItem value="Clinic staff">Clinic staff</MultiSelectItem>
<MultiSelectItem value="Night shift">Night shift</MultiSelectItem>
<MultiSelectItem value="Patients">Patients</MultiSelectItem>
</MultiSelect>
</Field>
</ul>
</Card>Turn the settings on and off by the switch, its label or Space: each change saves at once and the line under the list says so. Text alerts are refused and the switch goes back. The save is a timer; the refusal is our own rule (the sample account has no phone number).
Field avatar
What an agent sees
- FieldValueThe row's current value, shown before its control (an address before its edit button)
import { Field, FieldValue } from '@/components/ui/goop/field';
import { Card } from '@/components/ui/goop/card';
import { Switch } from '@/components/ui/goop/switch';
import { MultiSelect, MultiSelectItem } from '@/components/ui/goop/multi-select';
<Card variant="outline" asChild>
<ul>
<Field as="li" label="Weekly digest" description="A summary every Monday">
{(control) => <Switch {...control} />}
</Field>
<Field as="li" label="Who takes part" description="Every group the study recruits from" stack="always">
<MultiSelect defaultValue={['Clinic staff']} placeholder="Choose who takes part">
<MultiSelectItem value="Clinic staff">Clinic staff</MultiSelectItem>
<MultiSelectItem value="Night shift">Night shift</MultiSelectItem>
<MultiSelectItem value="Patients">Patients</MultiSelectItem>
</MultiSelect>
</Field>
</ul>
</Card>Press the round avatar (or Tab to it and press Enter) and choose a picture: it shows at once and uploads for a moment. A file over 2 MB or not a picture is refused in the row; Remove puts the initials back. The upload is a timer; the picture never leaves the page. The theme ships no picture chooser for this row: the avatar-as-button and its hidden file field are this example’s own composition.
Field button
What an agent sees
- FieldValueThe row's current value, shown before its control (an address before its edit button)
import { Field, FieldValue } from '@/components/ui/goop/field';
import { Card } from '@/components/ui/goop/card';
import { Switch } from '@/components/ui/goop/switch';
import { MultiSelect, MultiSelectItem } from '@/components/ui/goop/multi-select';
<Card variant="outline" asChild>
<ul>
<Field as="li" label="Weekly digest" description="A summary every Monday">
{(control) => <Switch {...control} />}
</Field>
<Field as="li" label="Who takes part" description="Every group the study recruits from" stack="always">
<MultiSelect defaultValue={['Clinic staff']} placeholder="Choose who takes part">
<MultiSelectItem value="Clinic staff">Clinic staff</MultiSelectItem>
<MultiSelectItem value="Night shift">Night shift</MultiSelectItem>
<MultiSelectItem value="Patients">Patients</MultiSelectItem>
</MultiSelect>
</Field>
</ul>
</Card>Press Export: the button is busy for a moment, then the row says the file is ready. Press Sign out: the other sessions end and the button switches off. Both are timers: no file is made and no one is signed out.
Field edit
What an agent sees
- FieldValueThe row's current value, shown before its control (an address before its edit button)
import { Field, FieldValue } from '@/components/ui/goop/field';
import { Card } from '@/components/ui/goop/card';
import { Switch } from '@/components/ui/goop/switch';
import { MultiSelect, MultiSelectItem } from '@/components/ui/goop/multi-select';
<Card variant="outline" asChild>
<ul>
<Field as="li" label="Weekly digest" description="A summary every Monday">
{(control) => <Switch {...control} />}
</Field>
<Field as="li" label="Who takes part" description="Every group the study recruits from" stack="always">
<MultiSelect defaultValue={['Clinic staff']} placeholder="Choose who takes part">
<MultiSelectItem value="Clinic staff">Clinic staff</MultiSelectItem>
<MultiSelectItem value="Night shift">Night shift</MultiSelectItem>
<MultiSelectItem value="Patients">Patients</MultiSelectItem>
</MultiSelect>
</Field>
</ul>
</Card>Press the pencil to edit the address in place and Save: an address without an @, or lucia@fieldwork.test (in use), is refused under the field; a good one is saved after a moment. Cancel or Escape leave it as it was; the focus returns to the pencil. The save is a timer; the address in use is our own sample.
Field icon
What an agent sees
- FieldValueThe row's current value, shown before its control (an address before its edit button)
import { Field, FieldValue } from '@/components/ui/goop/field';
import { Card } from '@/components/ui/goop/card';
import { Switch } from '@/components/ui/goop/switch';
import { MultiSelect, MultiSelectItem } from '@/components/ui/goop/multi-select';
<Card variant="outline" asChild>
<ul>
<Field as="li" label="Weekly digest" description="A summary every Monday">
{(control) => <Switch {...control} />}
</Field>
<Field as="li" label="Who takes part" description="Every group the study recruits from" stack="always">
<MultiSelect defaultValue={['Clinic staff']} placeholder="Choose who takes part">
<MultiSelectItem value="Clinic staff">Clinic staff</MultiSelectItem>
<MultiSelectItem value="Night shift">Night shift</MultiSelectItem>
<MultiSelectItem value="Patients">Patients</MultiSelectItem>
</MultiSelect>
</Field>
</ul>
</Card>Press an icon to cycle it and type the name; Look puts the pairs in two settings rows or bare as a form’s title line. In the rows, switch row or column, the hairline, stacking on a phone (seen under 641 px) and invalid; disable them in either. Nothing is saved; the picker cycles five icons instead of opening a list.
Field select
What an agent sees
- FieldValueThe row's current value, shown before its control (an address before its edit button)
import { Field, FieldValue } from '@/components/ui/goop/field';
import { Card } from '@/components/ui/goop/card';
import { Switch } from '@/components/ui/goop/switch';
import { MultiSelect, MultiSelectItem } from '@/components/ui/goop/multi-select';
<Card variant="outline" asChild>
<ul>
<Field as="li" label="Weekly digest" description="A summary every Monday">
{(control) => <Switch {...control} />}
</Field>
<Field as="li" label="Who takes part" description="Every group the study recruits from" stack="always">
<MultiSelect defaultValue={['Clinic staff']} placeholder="Choose who takes part">
<MultiSelectItem value="Clinic staff">Clinic staff</MultiSelectItem>
<MultiSelectItem value="Night shift">Night shift</MultiSelectItem>
<MultiSelectItem value="Patients">Patients</MultiSelectItem>
</MultiSelect>
</Field>
</ul>
</Card>Choose a start page or how names are shown: each choice saves at once (the line under the list says so) and the row’s description follows the name choice. The save is a timer; the name is our own sample.
Field stacked
What an agent sees
- FieldValueThe row's current value, shown before its control (an address before its edit button)
import { Field, FieldValue } from '@/components/ui/goop/field';
import { Card } from '@/components/ui/goop/card';
import { Switch } from '@/components/ui/goop/switch';
import { MultiSelect, MultiSelectItem } from '@/components/ui/goop/multi-select';
<Card variant="outline" asChild>
<ul>
<Field as="li" label="Weekly digest" description="A summary every Monday">
{(control) => <Switch {...control} />}
</Field>
<Field as="li" label="Who takes part" description="Every group the study recruits from" stack="always">
<MultiSelect defaultValue={['Clinic staff']} placeholder="Choose who takes part">
<MultiSelectItem value="Clinic staff">Clinic staff</MultiSelectItem>
<MultiSelectItem value="Night shift">Night shift</MultiSelectItem>
<MultiSelectItem value="Patients">Patients</MultiSelectItem>
</MultiSelect>
</Field>
</ul>
</Card>Type a start and an end; switch the column to a row, add a description, disable the fields, mark the end invalid. The times are not checked: "Invalid" only marks the end box.
Field tile
What an agent sees
- FieldValueThe row's current value, shown before its control (an address before its edit button)
import { Field, FieldValue } from '@/components/ui/goop/field';
import { Card } from '@/components/ui/goop/card';
import { Switch } from '@/components/ui/goop/switch';
import { MultiSelect, MultiSelectItem } from '@/components/ui/goop/multi-select';
<Card variant="outline" asChild>
<ul>
<Field as="li" label="Weekly digest" description="A summary every Monday">
{(control) => <Switch {...control} />}
</Field>
<Field as="li" label="Who takes part" description="Every group the study recruits from" stack="always">
<MultiSelect defaultValue={['Clinic staff']} placeholder="Choose who takes part">
<MultiSelectItem value="Clinic staff">Clinic staff</MultiSelectItem>
<MultiSelectItem value="Night shift">Night shift</MultiSelectItem>
<MultiSelectItem value="Patients">Patients</MultiSelectItem>
</MultiSelect>
</Field>
</ul>
</Card>Press a row’s words or its switch to turn it on; switch row or column, the hairline, stacking on a phone (seen under 641 px), disabled, the descriptions and the tiles. Nothing is saved: the rows only say their state.
When to use
- A form row that ties one control to its label, its description and its error line, as a settings row or a stacked form field.
- Also called: form field or form control.
Installation
Paste the prompt below into your coding agent. It reads Goop's install steps, installs the part and its tokens once, then reuses this same Field on every screen instead of drawing a new one: the same height, the same focus ring, the same spacing.
npx shadcn@4.23.1 add @goop/trail-fieldAdd the Goop Field to this project. The install steps are at https://goop.so/docs/install.mdUsage
import { Field, FieldValue } from '@/components/ui/goop/field';
import { Card } from '@/components/ui/goop/card';
import { Switch } from '@/components/ui/goop/switch';
import { MultiSelect, MultiSelectItem } from '@/components/ui/goop/multi-select';
<Card variant="outline" asChild>
<ul>
<Field as="li" label="Weekly digest" description="A summary every Monday">
{(control) => <Switch {...control} />}
</Field>
<Field as="li" label="Who takes part" description="Every group the study recruits from" stack="always">
<MultiSelect defaultValue={['Clinic staff']} placeholder="Choose who takes part">
<MultiSelectItem value="Clinic staff">Clinic staff</MultiSelectItem>
<MultiSelectItem value="Night shift">Night shift</MultiSelectItem>
<MultiSelectItem value="Patients">Patients</MultiSelectItem>
</MultiSelect>
</Field>
</ul>
</Card>- Fits: account, flow, settings, schedule (their recipes).
- Field is one piece:
labelanddescriptionare its props, with no label or description part to import, and a bare Field is a settings row (orientation="horizontal"); a form's label over its control isorientation="vertical". A row's control is one line tall: the row centres its words against it, so a tall control (a RadioGroup, a column of checkboxes) leaves the label floating at the row's middle, far from the first option on a wide page. Put a choice of a few short options in a Select in the row; put options that need their own words (a size and its price) inorientation="vertical"(the label over the group, the group named byaria-label), or under a heading of their own. - More on where it goes: field--options.md
- height, width, padding, gap, background, text: add no class for these.
API reference
| Option | Type | What it does |
|---|---|---|
| orientation | horizontal | vertical = horizontal |
- Each option with its sentence: field--options.md
- Another example of it: field-error.md, input-group.md, rating.md, textarea.md
| Part | What it is |
|---|---|
| FieldValue | The row's current value, shown before its control (an address before its edit button) |
- Class recipes (cva): fieldVariants (Field)
- data-slot values (to select a part by): field, field-content, field-control, field-description, field-label, field-media, field-value
Field: every option
import { Field } from '@/components/ui/goop/field';Compose
- A vertical field has no inside of its own: in a list of rows give the row
stack="always"instead; a group that is no Field (a ChoiceGroup) is held in anliwithp-4 max-narrow:px-2.5. - FieldValue: A value with its edit button:
<Field label="Email">{(control) => (<><FieldValue>sam@example.com</FieldValue> <IconButton … {...control}>…</IconButton></>)}</Field>. A value alone (a read-only fact) takes the control's id:<FieldValue id={control.id}>.
Options
- orientation: horizontal (default), vertical
- as?: 'div' | 'li' = 'div' —
limakes the row an item of its list (a settings list'sul); adivby default. - ref?: Ref<HTMLDivElement | HTMLLIElement> — The row's element: the
div, or theliwithas="li". - label: ReactNode — The control's name, shown over or before it; a click on it reaches the control.
- description?: ReactNode — A grey line under the label, read out with the control; none by default.
- separator?: boolean — The hairline under the row:
truedraws it always,falsenever; left out, it is drawn under every row but not under the last of its siblings. - disabled?: boolean — Dims the words to half and disables the control the field wires (a link takes no
disabled); off by default. - media?: ReactNode — What the row shows before its words — the theme's
IconTilemarking the row's subject. - stack?: boolean | 'always' — Whether the row stacks its words above its control:
"always"at every width (a MultiSelect, a Textarea or a long Select in a settings list);trueat or below 640 px;falsenever. - children: ReactElement<Partial<FieldControlProps>> | ((control: FieldControlProps) => ReactNode) — The control (a Switch, TextInput, Select, Textarea or Slider) or a function given its wiring.
- Another example of it: field-error.md, input-group.md, rating.md, textarea.md
- Types: FieldControlProps = { id: string; 'aria-describedby'?: string; disabled?: boolean }
Keyboard
| Key | What it does |
|---|---|
| Space | Toggle |
| ArrowDown ArrowUp | Move highlight |
| Enter | Choose highlighted |
| Escape | Dismiss |
Accessibility
- The part itself answers the keys above.
- hover, active, focus-visible, focus-within: the browser's own (:hover, :active, :focus-visible, :focus-within): write nothing
Its states are drawn from attributes and props, so assistive technology and your agent read the same thing:
| State | Drawn by |
|---|---|
| checked | the prop defaultChecked |
| disabled | the prop disabled |
Notes for AI
Give your coding agent this page as text instead of screenshots: the parts, the options, the states and the keys. An agent that reads the real part builds the real part, not a lookalike.