Forms

FormField

Wrapper primitive that pairs a single control with its label, description, and error and wires the ARIA association via context.

import { FormField } from '@lostgradient/cinder';
formwrapper
01

Overview

Reference usage

Wraps an input, label, and helper or error text into a cohesive accessible field unit.

Usage

svelte
<script lang="ts">
  import { FormField } from '@lostgradient/cinder';
  import { Input } from '@lostgradient/cinder';

  let name = $state('');
</script>

<FormField id="full-name" label="Full name" optional>
  <Input id="full-name" bind:value={name} placeholder="Jane Smith" />
</FormField>

Use either optional or required, never both. When both are supplied, Cinder renders the required marker.

Errors, notes and trailing content

An error leads with a warning glyph (a triangle) and sits under the control in a polite live region; errorGlyph="error" draws a circle instead, for a conflict such as a URL that is already connected. errorAction renders after the message in the same region, for a link ("Open GitHub") or a quiet Retry. warningAction does the same for a warning, after its words in the same paragraph ("Won’t run until a provider is connected, Connect a provider"). trailing shares the control's row, so a Try again button sits beside a field whose test failed. note is neutral text under the helper text, wired into aria-describedby, for why a field is cleared. managed leads with a lock glyph, and managed.message replaces the "Managed by" wording with a whole sentence. A label that wraps keeps its lines apart.

Live preview

Basic form field

Managed by Workspace policy: Displayed on shared reports

02

When to use

Use when
  • Composing a one-off field where the input does not own its own label rendering.
  • Forwarding shared required, disabled, and error state to an opted-in child control.
Avoid when
  • Grouping multiple related controls under one heading — use form-section instead.
03

Examples

Basic form field

A form field wrapping an input with label association.

Composed input — context inheritance

Input inside FormField inherits aria-describedby and aria-invalid from context.

Error with an action, and a trailing Try again

The error is the field’s own: a danger ring, a glyph and the message directly under the control. errorAction adds a link after the message in the accent colour (Open GitHub, with the circle glyph for a conflict), and trailing puts a button beside the field (Try again after a failed test).

Placeholder, description and note

note is neutral text under the description that says why a field is the way it is. Here the fixed-date field is cleared for a schedule, keeps its placeholder and help text, and explains itself beneath.

Form field with error

Error state wires aria-invalid and aria-describedby on the wrapped control.

04

Props

Props for form-field
Name
Type
Default
Description
id required text Required stable id — used for <label for>, description, error, and the child control's id via context.
label text Visible label text. Omit only when the child control supplies its own accessible name, such as via aria-label or aria-labelledby.
labelVisible boolean true Whether the label is visibly rendered. Set false to visually hide it while keeping it associated with the control.
description text Helper text rendered below the control; wired into aria-describedby.
descriptionAction Snippet | undefined Rendered after the helper text inside the same paragraph, so it joins aria-describedby: a quiet link such as "Where do I get one?". Shown only with description.
warning text Advisory for a legal but potentially risky value; does not mark the control invalid.
warningAction Snippet | undefined Rendered after the warning inside the same paragraph, such as a link to fix what it says ("Connect a provider").
error text Validation error; sets aria-invalid="true" on opted-in controls via context.
errorGlyph 'warning' | 'error' | undefined 'warning' The glyph drawn before the error message: warning (a triangle, the default) for a value the person can fix, or error (a circle) for a conflict such as a URL that is already connected.
errorAction Snippet | undefined Rendered after the error message inside the same live region, such as a link to the record that conflicts ("Open GitHub") or a quiet Retry.
note text Neutral explanation drawn under the helper text and wired into aria-describedby, such as why a field is cleared. Not an error and not a warning.
trailing Snippet | undefined Rendered beside the control on the same row, such as a Try again button after a failed test. The control takes the room the trailing content leaves.
managed { /** Policy or administrator that owns the value. */ by?: string | undefined; /** Human-readable explanation for the constraint. */ reason?: string | u…
Show full type { /** Policy or administrator that owns the value. */ by?: string | undefined; /** Human-readable explanation for the constraint. */ reason?: string | undefined; /** The whole line to show beside the lock glyph, replacing the "Managed by" wording, such as "Locked by your deployment (remote mode). Change it in the deployment's configuration." */ message?: string | undefined; }
Policy ownership metadata displayed without disabling the control.
required boolean false Renders a visual required marker and exposes required: true on the context.
optional boolean false Appends "Optional" to the visible label. Do not combine with required; required wins.
disabled boolean false Propagated to opted-in controls via context. Does not style FormField itself.
children required snippet Control(s) rendered inside the field.