Back to Components

Foundation

Field

Labeled form-field wrapper. Auto-generates an id and exposes ARIA wiring (id, aria-describedby, aria-invalid) via the children snippet.

Examples

With description

We'll only use this for password resets.

<Field
  label="Email"
  description="We'll only use this for password resets."
  required
>
  {#snippet children({id, describedBy})}
    <Input {id} type="email" placeholder="[email protected]" aria-describedby={describedBy} />
  {/snippet}
</Field>

With error

<Field label="Username" error="That username is already taken.">
  {#snippet children({id, describedBy, invalid})}
    <Input {id} value="taken-name" aria-describedby={describedBy} aria-invalid={invalid || undefined} />
  {/snippet}
</Field>

With Textarea

Markdown supported. 280 char max.

<Field label="Bio" description="Markdown supported. 280 char max.">
  {#snippet children({id, describedBy})}
    <Textarea {id} placeholder="Tell us about yourself" aria-describedby={describedBy} />
  {/snippet}
</Field>

Props

PropTypeDefaultDescription
labelstringRenders a Label above the control linked by id.
descriptionstringHelper text below the control. Hidden when error is set.
errorstringError message; flips invalid state and replaces description.
requiredbooleanfalseAdds a required marker on the label.
idstringOverride auto-generated id (default: uin-field-N counter).
childrenSnippet<[{id, describedBy, invalid}]>Receives wiring args; pass them to the control.

Install

CLI

npx @a3tai/mittsu add field