suiss/ui · Component
Field
Building blocks for form fields that pair controls with labels, descriptions and error messages.
Field is an open-source component from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
A Field wraps one control together with its FieldLabel, an optional FieldDescription and an optional FieldError. It automatically adds the ids of its descriptions and errors to the control's aria-describedby, so supporting text is announced with the control. Use FieldContent to stack a label and description beside a control in a horizontal field, and FieldTitle for a non-label heading inside a field.
FieldGroup stacks fields with consistent spacing, and its inset variant groups them into a rounded list, like iOS Settings. FieldSet and FieldLegend group related fields under a caption, and FieldSeparator divides sections, optionally with text. Use these parts with any control in the library, such as Input, Textarea, Checkbox, Switch or RadioGroup.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Usage
Composition
Use the following composition to build a Field:
Examples
With help link
A description that contains a link, styled with text-primary and an underline.
Inset
Set variant="inset" on FieldGroup to put horizontal fields in a rounded settings list with separators.
With textarea
A field that labels and describes a Textarea.
Invalid
Set aria-invalid on the control and render a FieldError with the message. The error is announced as an alert.
Multiple errors
Pass an errors array to FieldError to render the messages as a bulleted list.
Disabled
Set data-disabled on the Field to dim its label when the control is disabled.
Horizontal
Set orientation="horizontal" to place the label beside the control, here a checkbox and a switch. One field holds its label and description in FieldContent.
Choice cards
Place a horizontal Field inside a FieldLabel to present radio options as selectable cards. The label gets a border, and a highlighted ring when the control inside it is checked.
Form
A complete payment form built from field sets, groups, a separator and actions.
Large
Set size="lg" on Field for forms such as sign-in pages: the label turns 13px, medium weight and muted, and sits 8px above the control. Pair it with lg inputs and a form button.
Separator with text
Pass text as the children of FieldSeparator to center it on the line, here between a sign-in button and an email field.
Accessibility
Fieldhas thegrouprole and links its descriptions and errors to its first control througharia-describedby, updating the link when they change.FieldSetrenders a nativefieldset, which takes its accessible name fromFieldLegend.FieldErrorhas thealertrole, so assistive technology announces it when it appears. It renders nothing when it has no children and no errors.- Set
aria-invalidon the control to mark it invalid;FieldErrordoes not set it for you. - Clicking a
FieldLabelfocuses or toggles its associated control.
API Reference
FieldSet
Groups related fields in a native fieldset.
Also accepts the props of React.ComponentProps<"fieldset">.
FieldLegend
The caption of a field set.
| Prop | Type | Default |
|---|---|---|
variant | "legend" | "label" | "legend" |
Also accepts the props of React.ComponentProps<"legend">.
variant sets data-variant so the legend can be styled as a section caption or as a field label.
FieldGroup
Stacks fields with consistent spacing, or groups them into an inset list.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "inset" | "default" |
Also accepts the props of React.ComponentProps<"div">.
The inset variant groups the fields into a rounded list on bg-muted, with separators between rows and inputs aligned to the end. The group sets data-variant and is a container query context named field-group, which drives the responsive orientation of its fields.
Field
Wraps a single control with its label, description and error.
| Prop | Type | Default |
|---|---|---|
orientation | "vertical" | "horizontal" | "responsive" | "vertical" |
size | "default" | "lg" | "default" |
Also accepts the props of React.ComponentProps<"div">.
vertical stacks the label above the control, horizontal places them side by side, and responsive switches to horizontal when the surrounding FieldGroup is wide enough. lg makes the label 13px, medium weight and muted, and brings it 8px from the control. The field sets data-orientation and data-size.
FieldContent
Stacks a label and description next to a control in a horizontal field.
Also accepts the props of React.ComponentProps<"div">.
FieldLabel
The label of a field's control.
Also accepts the props of React.ComponentProps<typeof Label>.
Connect each FieldLabel to its control with htmlFor and id.
FieldTitle
A heading inside a field that is not a label, such as the title of a choice card.
Also accepts the props of React.ComponentProps<"div">.
FieldDescription
Supporting text that describes the control.
Also accepts the props of React.ComponentProps<"p">.
FieldSeparator
A divider between sections, with optional centered text.
| Prop | Type | Default |
|---|---|---|
children | React.ReactNode | - |
Also accepts the props of React.ComponentProps<"div">.
FieldError
An error message for the field.
| Prop | Type | Default |
|---|---|---|
errors | Array<{ message?: string } | undefined> | - |
Also accepts the props of React.ComponentProps<"div">.
Pass children or an errors array. Duplicate messages are removed; one message renders as text and several render as a list. errors is ignored when children are provided.
Each part sets a data-slot, such as field, field-group or field-error, for styling. FieldTitle shares the field-label slot with FieldLabel.
Web preview
Field wraps one control, such as an Input, Textarea or Switch, with a FieldLabel, an optional FieldDescription and a FieldError. It shares the field's disabled and invalid state with the control and handles validation: required values, length limits and custom validate functions, checked on submit, blur or change.
FieldSet and FieldLegend group related fields under a heading, and FieldGroup stacks fields. The inset variant of FieldGroup turns the fields into rows on a rounded bg-muted surface with hairlines between them, like a settings list.
Installation
The CLI also adds what it builds on: Separator.
- Install the following dependencies:
-
Add the pieces it builds on: Separator.
-
Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/field.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
-
Add the pieces it builds on: Separator.
-
Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/field.tsx:
- Update the import paths to match your project setup.
-
Add the pieces it builds on: Separator.
-
Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/field.tsx:
- Update the import paths to match your project setup.
-
Target iOS 17 or later.
-
Copy the theme files every view uses:
- Copy the source and every file it uses:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Examples
Invalid
A field in the invalid state with an error message.
Set invalid to force the error state, or let validation decide it.
Web preview
Validation
Required, custom and minimum-length validation on blur and on change.

Disabled
A disabled field.
Web preview
Horizontal
Switch rows with a title and description beside the control.
Use orientation="horizontal" for a label beside a switch or checkbox, with FieldContent holding a FieldTitle and FieldDescription.
Web preview
Checkbox group
A fieldset of checkboxes with a legend.

Inset
An inset group of rows on a rounded surface.
Web preview
This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.
Form
A complete form with validation and a submit button.
Web preview
Large
Field with size="lg", lg inputs and a full-width form button, for sign-in screens.
Web preview
Accessibility
- The control is labelled by
FieldLabeland gets the description and error text as its accessibility hint. FieldErrorhas thealertrole, so screen readers announce it when it appears.FieldSethas thegrouprole labelled by its legend; the legend has theheaderrole.- Disabled state is passed to the label and control.
API Reference
FieldSet
Group of related fields.
Also accepts the props of React.ComponentProps<typeof FieldsetPrimitive.Root>.
FieldLegend
Heading for a fieldset.
| Prop | Type | Default |
|---|---|---|
variant | "legend" | "label" | "legend" |
Also accepts the props of React.ComponentProps<typeof FieldsetPrimitive.Legend>.
FieldGroup
Stack of fields, plain or inset.
| Prop | Type | Default |
|---|---|---|
variant | FieldGroupVariant | "default" |
Also accepts the props of React.ComponentProps<typeof View>.
variant is default or inset. Inset separators use start and end offsets, so they flip in right-to-left layouts.
Field
One field that shares state with its control.
| Prop | Type | Default |
|---|---|---|
orientation | FieldOrientation | "vertical" |
size | "default" | "lg" | "default" |
Also accepts the props of React.ComponentProps<typeof FieldPrimitive.Root>.
orientation is vertical, horizontal or responsive. lg makes the label 13 point, medium weight and muted, 8 points above the control. Put a FieldLabel, the control and a FieldError inside Field. The control is labelled by the label and uses the description and error text as its accessibility hint.
FieldContent
Column for a title and description beside a control.
Also accepts the props of React.ComponentProps<typeof View>.
FieldLabel
Label linked to the control.
Also accepts the props of React.ComponentProps<typeof FieldPrimitive.Label>.
FieldTitle
Bold text for a field's title.
Also accepts the props of React.ComponentProps<typeof RNText>.
FieldDescription
Helper text.
Also accepts the props of React.ComponentProps<typeof FieldPrimitive.Description>.
FieldSeparator
Divider with optional centered text.
| Prop | Type | Default |
|---|---|---|
children | React.ReactNode | - |
Also accepts the props of React.ComponentProps<typeof View>.
FieldSeparator divides fields and can show short text such as "or" in the middle.
FieldError
Error message shown when validation fails.
| Prop | Type | Default |
|---|---|---|
errors | Array<{ message?: string } | undefined> | - |
Also accepts the props of React.ComponentProps<typeof FieldPrimitive.Error>.
FieldError shows its children, or the messages from errors, an array of { message } objects (for example from a form library). Limit it to one failure with match, such as tooShort.
.invalid
| Parameter | Type | Default |
|---|---|---|
_ isInvalid | Bool | true |
FieldOrientation
Values: .vertical, .horizontal.
FieldSize
Values: .default, .lg.
Field
One field that shares state with its control.
| Parameter | Type | Default |
|---|---|---|
orientation | FieldOrientation: .vertical | .horizontal | .vertical |
size | Size: .default | .lg | .default |
invalid | Bool? | nil |
content | () -> Content | - |
FieldContent
Column for a title and description beside a control.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
FieldTitle
Bold text for a field's title.
| Parameter | Type | Default |
|---|---|---|
_ title | LocalizedStringKey | - |
FieldDescription
Helper text.
| Parameter | Type | Default |
|---|---|---|
_ description | LocalizedStringKey | - |
FieldError
Error message shown when validation fails.
| Parameter | Type | Default |
|---|---|---|
_ message | LocalizedStringKey | - |
errors | [String?] | - |
Overloads: init(_:), init(errors:).
FieldGroupVariant
Values: .default, .inset.
FieldGroup
Stack of fields, plain or inset.
| Parameter | Type | Default |
|---|---|---|
_ variant | FieldGroupVariant: .default | .inset | .default |
content | () -> Content | - |
FieldSet
Group of related fields.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
FieldLegend
Heading for a fieldset.
| Parameter | Type | Default |
|---|---|---|
_ title | LocalizedStringKey | - |
variant | Variant: .legend | .label | .legend |
FieldSeparator
Divider with optional centered text.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
_ title | LocalizedStringKey | - |
Overloads: init(content:), init(), init(_:).
FieldOrientation
Values: Vertical, Horizontal, Responsive.
FieldGroupVariant
Values: Default, Inset.
FieldLegendVariant
Values: Legend, Label.
FieldSize
Values: Default, Lg.
FieldScope.weight
Receiver: Modifier.
| Parameter | Type | Default |
|---|---|---|
weight | Float | - |
Returns Modifier.
FieldSet
Group of related fields.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
variant | FieldGroupVariant: Default | Inset | FieldGroupVariant.Default |
enabled | Boolean | true |
content | @Composable ColumnScope.() -> Unit | - |
FieldLegend
Heading for a fieldset.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |
variant | FieldLegendVariant: Legend | Label | FieldLegendVariant.Legend |
FieldGroup
Stack of fields, plain or inset.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
variant | FieldGroupVariant: Default | Inset | FieldGroupVariant.Default |
content | @Composable () -> Unit | - |
Field
One field that shares state with its control.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
orientation | FieldOrientation: Vertical | Horizontal | Responsive | FieldOrientation.Vertical |
size | FieldSize: Default | Lg | FieldSize.Default |
enabled | Boolean | LocalFieldState.current.enabled |
invalid | Boolean | false |
content | @Composable FieldScope.() -> Unit | - |
FieldContent
Column for a title and description beside a control.
Receiver: FieldScope.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
content | @Composable ColumnScope.() -> Unit | - |
FieldLabel
Label linked to the control.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |
FieldTitle
Bold text for a field's title.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |
FieldDescription
Helper text.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |
FieldSeparator
Divider with optional centered text.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
text | String? | null |
FieldError
Error message shown when validation fails.
| Parameter | Type | Default |
|---|---|---|
text | String? | - |
modifier | Modifier | Modifier |
errors | List<String?> | - |
Overloads: FieldError(text), FieldError(errors).

