Skip to content

Form Field

SFormField is a form field wrapper: a label (via SLabel), a hint or error message, and correct a11y relationships (for, aria-describedby, aria-invalid). The control goes into the default slot and receives the scoped props { id, describedBy, invalid }. SInput, SSelect, and STextarea are built on this block — composition instead of duplicated markup.

Basic usage

How should we address you?

Error state

This field is required

Sizes

The size prop (sm / md / lg) is passed to the label (SLabel) and changes its typography. The size of the control itself is managed separately, on the control's side.

Label from markup

The label prop takes a string. When the label has to be built from elements — made a link, or given a hint icon — use the #label slot: its content goes inside the same <label for>, so clicking it still focuses the field.

$
Limit: $1,000

The slot is incompatible with a floating label: that label is drawn by the field itself, not by SFormField. In dev mode this combination logs a warning — pass floating-label="false".

API

Props

NameTypeDefaultDescription
labelstringundefinedField label (rendered via SLabel).
hintstringundefinedHint below the field.
errorstringundefinedError message. When set, the field is marked invalid.
invalidbooleanfalseExplicitly marks the field invalid (in addition to error).
requiredbooleanfalseRequired field: a * marker next to the label.
idstringundefinedId of the controlled element. Generated when omitted (SSR-safe).
size"md" | "sm" | "lg""md"Size (passed to the label).
floating-labelbooleanfalseFloating label: the top label is NOT rendered — the field draws the label inside its border itself (see the floatingLabel slot prop). The hint/error layout stays the same.
squarebooleanfalseSquare corners: removes the field border radius (rounded by default).
inlinebooleanfalseThe field takes the content width instead of the full row. For compact controls (checkbox, switch) that need a hint and an error but no stretched block.

Slots

NameDescription
defaultThe control. Receives the scoped props { id, labelId, describedBy, invalid, label, floatingLabel, square }.
labelField label as markup, when a string label is not enough (a link label, a tooltip icon). The content goes inside the same <label for>, so clicking it also focuses the field. Takes precedence over the label prop; does not combine with a floating label, which the field draws itself.