Two-column layout
Grid places two short fields side by side and one full-width.
<Grid columns={2} gap="md">
<Field name="firstName">
<Field.Label>First Name</Field.Label>
<Input placeholder="Jane" />
</Field>
<Field name="lastName">Owns the label, description and error for one form control.
<Field name="email">
<Field.Label>Email address</Field.Label>
<Input type="email" placeholder="jane@example.com" />
<Field.Description>We will never share your email.</Field.Description>
</Field>pnpm add @usefragments/uiImport styles once from @usefragments/ui/styles. See the installation guide for framework and theme setup.
Import Field once, then compose its parts with dot notation.
Field.LabelField.ControlField.DescriptionField.ErrorField.ValidityField.RequiredLabel, control and description wired together.
<Field name="email">
<Field.Label>Email address</Field.Label>
<Input type="email" placeholder="jane@example.com" />
<Field.Description>We will never share your email.</Field.Description>
</Field>Grid places two short fields side by side and one full-width.
<Grid columns={2} gap="md">
<Field name="firstName">
<Field.Label>First Name</Field.Label>
<Input placeholder="Jane" />
</Field>
<Field name="lastName">invalid marks the field failed and reveals Field.Error.
<Field name="username" invalid>
<Field.Label>Username</Field.Label>
<Input defaultValue="ada lovelace" />
<Field.Error match>Usernames cannot contain spaces</Field.Error>
</Field>The trigger takes the label; the error lands under it.
<Field name="team" invalid>
<Field.Label>Team</Field.Label>
<Select placeholder="Choose a team">
<Select.Trigger />
<Select.Content>
<Select.Item value="design">Design</Select.Item>validate runs on change and feeds Field.Error.
<Field
name="age"
validate={(value) => {
const num = Number(value);
if (isNaN(num) || num < 18) return 'Must be 18 or older';
return null;Prop | Type | Default | Description |
|---|---|---|---|
childrenRequired | React.ReactNode | Not set | Field content (Label, Control, Description, Error) |
Control.childrenRequired | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Not set | — |
Control.className | string | undefined | Not set | — |
Description.childrenRequired | React.ReactNode | Not set | — |
Description.className | string | undefined | Not set | — |
disabled | boolean | undefined | Not set | Disables the field: dimmed once, and its control cannot be used |
Error.children | React.ReactNode | Not set | What went wrong and how to fix it. Omit to show the browser's validation message. |
Error.className | string | undefined | Not set | — |
Error.match | boolean | "valueMissing" | "typeMismatch" | "tooShort" | "tooLong" | "patternMismatch" | "customError" | undefined | Not set | — |
invalid | boolean | undefined | Not set | Marks the field invalid: the control takes the danger edge and Field.Error shows |
Label.childrenRequired | React.ReactNode | Not set | — |
Label.className | string | undefined | Not set | — |
name | string | undefined | Not set | Field name, used for error distribution from Form |
Required.children | React.ReactNode | Not set | — |
validate | ((value: unknown) => string | string[] | null | Promise<string | string[] | null>) | undefined | Not set | Custom validation function returning error string(s) or null |
validationDebounceTime | number | undefined | Not set | Debounce time in ms for onChange validation |
validationMode | "onBlur" | "onChange" | "onSubmit" | undefinedonBluronChangeonSubmit | Not set | When to trigger validation |
Validity.childrenRequired | (state: FieldValidityState) => React.ReactNode | Not set | — |