How to use
FormFieldSet is one component that dispatches to 12 different field implementations based on its type prop — text, number, email, password, select, radio, checkbox, switch, date picker, phone, file, and more — sharing one validation system and one Form context, so every field type is styled, labeled, and validated consistently without hand-building 12 separate wrappers.
import { Form, FormFieldSet } from "oks-ui";type picks the field implementation; every other prop after that is shared (label, description, size, variant, color, labelPlacement) plus whichever props are specific to that type (options for select/radio/checkbox, length for otp, accept for file). FormFieldSet must live inside a Form for validation/submission to work — it registers itself with the nearest Form context on mount.
<Form onSubmit={(data) => console.log(data)}>
<FormFieldSet type="text" name="name" label="Name" />
<FormFieldSet type="email" name="email" label="Email" validation={{ rules: { required: true, email: true } }} />
<FormFieldSet
type="select"
name="role"
label="Role"
options={[
{ label: "Admin", value: "admin" },
{ label: "Editor", value: "editor" },
{ label: "Viewer", value: "viewer" },
]}
/>
<FormFieldSet type="switch" name="notifications" label="Email notifications" />
<Button type="submit">Save</Button>
</Form>validation.rules covers the common cases declaratively — required, email, minLength/maxLength, min/max, pattern, and a custom function rule for anything bespoke. Errors are computed by Form and shown per-field automatically once a field is touched (or immediately, depending on Form's showErrorsOn setting).
<FormFieldSet
type="password"
name="password"
label="Password"
validation={{
rules: {
required: true,
minLength: 8,
custom: (value) => /[A-Z]/.test(String(value)) || "Needs at least one uppercase letter",
},
}}
/>Every field type works both ways: pass value + onChange for a fully controlled field, or defaultValue and let Form track the value internally through its own formData state — the same convention across all 12 types, so switching a field between controlled and uncontrolled doesn't change how you read its value elsewhere (Form's formData always reflects the current value either way).
labelPlacement controls where the label sits relative to the control — top (the default), left, right, or floating (the label starts inside the control and animates up once it has a value or focus). All 12 field types support the full set.
<FormFieldSet type="text" name="company" label="Company" labelPlacement="floating" />
<FormFieldSet type="text" name="role" label="Role" labelPlacement="left" />For a variable-length group of fields (a list of email addresses, multiple phone numbers), LoopFields handles the add/remove/reindex bookkeeping — each item gets a stable identity across removals so validation state and values stay attached to the right item, not just the right position.
<LoopFields name="emails" minItems={1}>
{({ index, name }) => (
<FormFieldSet type="email" name={`${name}`} label={`Email ${index + 1}`} />
)}
</LoopFields>All available props for FormFieldSet. See the full component page for an interactive playground.
| Prop | Type | Default | Description |
|---|---|---|---|
onChange | (value: string) => void | — | Called with the input's resolved string value. |
onChange
(value: string) => void
Default: —
Called with the input's resolved string value.
| Prop | Type | Default | Description |
|---|---|---|---|
revealToggle | boolean | true | Shows the "eye" reveal toggle. |
strongPassword | { minLength?; minUpper?; minLower?; minNumber?; minSpecial? } | — | Enables a live requirements checklist while focused. |
disabled | boolean | false | Disables the control. |
required | boolean | false | Marks the field required. |
revealToggle
boolean
Default: true
Shows the "eye" reveal toggle.
strongPassword
{ minLength?; minUpper?; minLower?; minNumber?; minSpecial? }
Default: —
Enables a live requirements checklist while focused.
disabled
boolean
Default: false
Disables the control.
required
boolean
Default: false
Marks the field required.
| Prop | Type | Default | Description |
|---|---|---|---|
placeholder | string | — | Placeholder text. |
startIcon / endIcon | ReactNode | — | Leading icon / trailing icon (in addition to the reveal toggle). |
prefix / suffix | ReactNode | — | Leading/trailing affix. |
label | ReactNode | — | Field label. |
description | ReactNode | — | Helper text below the control. |
error | ReactNode | boolean | — | Error message, or true for an invalid state with no message. |
placeholder
string
Default: —
Placeholder text.
startIcon / endIcon
ReactNode
Default: —
Leading icon / trailing icon (in addition to the reveal toggle).
prefix / suffix
ReactNode
Default: —
Leading/trailing affix.
label
ReactNode
Default: —
Field label.
description
ReactNode
Default: —
Helper text below the control.
error
ReactNode | boolean
Default: —
Error message, or true for an invalid state with no message.
| Prop | Type | Default | Description |
|---|---|---|---|
size | "xs" | "xs-sm" | "sm" | "md" | "lg" | "xl" | "md" | Control size. |
variant | "bordered" | "soft" | "filled" | "underlined" | "bordered" | Visual variant. "filled" (text types) is borderless with a neutral fill at rest, border + ring on focus; other field types fall back to "bordered". "default"/"underline" are legacy aliases. |
color | "default" | "primary" | "secondary" | "info" | "success" | "warning" | "danger" | string | "default" | Semantic tone. |
colorDepth | number | 500 | Shade depth for color. |
radius | "none" | "xs" | "xs-sm" | "sm" | "md" | "lg" | "full" | "md" | Corner radius. `rounded` is a legacy alias. |
size
"xs" | "xs-sm" | "sm" | "md" | "lg" | "xl"
Default: "md"
Control size.
variant
"bordered" | "soft" | "filled" | "underlined"
Default: "bordered"
Visual variant. "filled" (text types) is borderless with a neutral fill at rest, border + ring on focus; other field types fall back to "bordered". "default"/"underline" are legacy aliases.
color
"default" | "primary" | "secondary" | "info" | "success" | "warning" | "danger" | string
Default: "default"
Semantic tone.
colorDepth
number
Default: 500
Shade depth for color.
radius
"none" | "xs" | "xs-sm" | "sm" | "md" | "lg" | "full"
Default: "md"
Corner radius. `rounded` is a legacy alias.
| Prop | Type | Default | Description |
|---|---|---|---|
labelPlacement | "top" | "left" | "right" | "floating" | "top" | Label position relative to the control. |
colSpan | number | — | Sets `grid-column: span N` on the field wrapper — a real home for a layout hint in a spread config object (instead of leaking to the <input>). |
labelPlacement
"top" | "left" | "right" | "floating"
Default: "top"
Label position relative to the control.
colSpan
number
Default: —
Sets `grid-column: span N` on the field wrapper — a real home for a layout hint in a spread config object (instead of leaking to the <input>).
| Prop | Type | Default | Description |
|---|---|---|---|
wrapperClassName | string | — | Class on the field wrapper (the element that also carries colSpan), separate from `className` on the control. |
className | string | — | Class applied to the root element. |
style | CSSProperties | — | Inline styles for the root element. |
wrapperClassName
string
Default: —
Class on the field wrapper (the element that also carries colSpan), separate from `className` on the control.
className
string
Default: —
Class applied to the root element.
style
CSSProperties
Default: —
Inline styles for the root element.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | FormFieldSet fields and other form content. |
children
ReactNode
Default: —
FormFieldSet fields and other form content.
| Prop | Type | Default | Description |
|---|---|---|---|
validationMode | "blur" | "change" | "blur" | When fields are (re-)validated. |
showErrorsOn | "blur" | "change" | "blur" | When validation errors start showing. |
validateOnMount | boolean | false | Runs validation immediately on mount. |
initialValues | FormData | {} | Initial values for uncontrolled fields. |
disableAutofill | boolean | true | Adds autocomplete/autofill-defeating attributes to the form. |
validationMode
"blur" | "change"
Default: "blur"
When fields are (re-)validated.
showErrorsOn
"blur" | "change"
Default: "blur"
When validation errors start showing.
validateOnMount
boolean
Default: false
Runs validation immediately on mount.
initialValues
FormData
Default: {}
Initial values for uncontrolled fields.
disableAutofill
boolean
Default: true
Adds autocomplete/autofill-defeating attributes to the form.
| Prop | Type | Default | Description |
|---|---|---|---|
onSubmit | (formData: FormData) => void | Promise<void> | — | Called with collected field values on submit (required). |
onError | (errors: FormErrors) => void | — | Called when submit is blocked by validation errors. |
onSubmit
(formData: FormData) => void | Promise<void>
Default: —
Called with collected field values on submit (required).
onError
(errors: FormErrors) => void
Default: —
Called when submit is blocked by validation errors.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | "" | Class applied to the form element. |
className
string
Default: ""
Class applied to the form element.