Field
NewCombine labels, controls, help text, and errors into accessible form fields.
Preview
Installation
npx sigma-ui@latest add fieldUsage
<script setup lang="ts">
import { Field, FieldDescription, FieldError, FieldGroup, FieldLabel } from '@/components/ui/field';
import { Input } from '@/components/ui/input';
</script>
<template>
<FieldGroup>
<Field>
<FieldLabel for="name">Name</FieldLabel>
<Input id="name" />
<FieldDescription>Shown on your profile.</FieldDescription>
</Field>
</FieldGroup>
</template>Field wraps one control with its label, description, and error. Set orientation to vertical, horizontal, or responsive.
FieldLabellabels the control. Wrap a wholeFieldwith it to build a selectable card.FieldDescriptionis helper text under the control or inside aFieldSet.FieldErrorshows error text from theerrorsprop or the default slot.FieldContentstacks a label and a description next to a checkbox, radio, or switch.FieldTitleis a title that is not tied to a single control.FieldSetandFieldLegendgroup related fields in afieldset.FieldGroupstacks fields and is the container theresponsiveorientation measures.FieldSeparatordivides groups, with optional text.
Responsive orientation
orientation="responsive" stacks the label above the control in narrow containers and places them side by side when the parent FieldGroup is at least 28rem wide. It uses a container query, so it reacts to the width of the form, not the viewport.
Examples
Validation
Set invalid on Field and pass messages to FieldError. errors accepts strings or objects with a message, so validation issues from libraries such as Zod or VeeValidate can be passed directly. Duplicates and empty values are skipped.
Choice card
Wrap a Field in FieldLabel to make the whole card clickable. The card is highlighted when the control inside it is checked.
Responsive
API Reference
Field
Props
| Prop | Type | Default |
|---|---|---|
orientationLayout of the label and the control. | "vertical" | "horizontal" | "responsive" | null | "vertical" |
invalidMarks the field as invalid and colors its label and description. | boolean | false |
disabledDims the label to match a disabled control. | boolean | false |
Slots
| Slot | Scope |
|---|---|
defaultField parts: | - |
FieldContent
Slots
| Slot | Scope |
|---|---|
default
| - |
FieldDescription
Slots
| Slot | Scope |
|---|---|
defaultHelper text. Links inside it are underlined. | - |
FieldError
Props
| Prop | Type | Default |
|---|---|---|
errorsError messages to show. Accepts strings or objects with a | FieldErrorItem[] | - |
Slots
| Slot | Scope |
|---|---|
defaultCustom error content. Replaces the | - |
FieldGroup
Slots
| Slot | Scope |
|---|---|
default
| - |
FieldLabel
Props
| Prop | Type | Default |
|---|---|---|
forThe id of the element the label is associated with. | string | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultLabel text. Wrap a whole | - |
FieldLegend
Props
| Prop | Type | Default |
|---|---|---|
variant
| "label" | "legend" | "legend" |
Slots
| Slot | Scope |
|---|---|
defaultLegend text of the | - |
FieldSeparator
Slots
| Slot | Scope |
|---|---|
defaultOptional text shown in the middle of the line, such as "Or continue with". | - |
FieldSet
Slots
| Slot | Scope |
|---|---|
defaultA | - |
FieldTitle
Slots
| Slot | Scope |
|---|---|
defaultTitle text. Use instead of | - |
Accessibility
Field renders role="group". FieldSet renders a native fieldset, which also disables every control inside it when it has the disabled attribute. FieldError renders role="alert".
Set the for attribute of FieldLabel to the id of the control. Set aria-invalid on the control together with invalid on Field, so screen readers announce the error state.
| Key | Description |
|---|---|
| Tab | Moves focus to the control inside the field. |