Encapsulate input elements with labels, descriptions, and validation.
import { Field, Input } from '@fluxui-dev/react';<Field name="email"> <Field.Label>Email</Field.Label> <Input type="email" /> <Field.Error /></Field>
Because using the field component in its full form can be verbose and repetitive, all form controls in Flux allow you to pass a label and a description prop directly. Under the hood, they will be wrapped in a field with an error component automatically.
<Input name="email" label="Email" type="email" />
Every field shows the validation error for its name, from the surrounding Inertia <Form> or the page's errors. See the Inertia guide.
<Form {...store.form()}> <Input label="Email" type="email" name="email" /> <Input label="Password" type="password" name="password" /></Form>
Wrap the control in Field and write Field.Label, Field.Description, or Field.Error yourself to pass them props such as srOnly or className; the field still looks up the validation error for its name.
import { Field, Otp } from '@fluxui-dev/react';<Field name="code" error="The code field must be 6 characters."> <Field.Label srOnly>Authentication code</Field.Label> <Otp name="code" length={6} className="mx-auto" /> <Field.Error className="text-center" /></Field>
A control's className stays on the control when label is set, so a margin lands between the label and the control, as in Flux for Blade. To space the whole field, write the Field yourself and pass it className.
<Field name="email" className="mt-6"> <Field.Label>Email</Field.Label> <Input type="email" /> <Field.Error /></Field>
Pass a message to the error prop to mark the control invalid and display it in Field.Error, taking precedence over the error looked up by name.
<Field error="The email field must be a valid email address."> <Field.Label>Email</Field.Label> <Input type="email" defaultValue="caleb@" /> <Field.Error /></Field>
Position the field description directly below the input, or pass descriptionTrailing to the control.
<Field name="password"> <Field.Label>Password</Field.Label> <Input type="password" /> <Field.Error /> <Field.Description>Must be at least 8 characters long, include an uppercase letter, a number, and a special character.</Field.Description></Field>
Badges allow you to enhance a field with additional information such as being "required" or "optional" when it might not be expected.
<Field name="email"> <Field.Label badge="Required">Email</Field.Label> <Input type="email" required /> <Field.Error /></Field><Field name="phone"> <Field.Label badge="Optional">Phone number</Field.Label> <Input type="tel" placeholder="(555) 555-5555" /> <Field.Error /></Field>
Display multiple fields horizontally in the same row.
<div className="grid grid-cols-2 gap-4"> <Input label="First name" placeholder="River" /> <Input label="Last name" placeholder="Porzio" /></div>
A container component that provides structure for form inputs with labels, descriptions, and error messages.
|
Prop
|
Description
|
|---|---|
| variant |
Visual style variant. Options: block, inline, bare (no spacing). Default: block.
|
| name |
Field name used to name the control inside and look up its validation error from FluxProvider's errors.
|
| error |
Error message that marks the control invalid and renders in Field.Error, defaulting to the validation error for the field's name.
|
| invalid |
Marks the control invalid without an error message, taking precedence over error.
|
| disabled |
Disables the control inside the field and dims its label.
|
| className |
CSS classes applied to the root element, which wraps the label, control, and error, such as a margin around the whole field.
|
|
Slot
|
Description
|
|---|---|
| children |
The form control elements (input, checkbox, etc.) and their associated labels, descriptions, and error messages.
|
|
Attribute
|
Description
|
|---|---|
| data-flux-field |
Applied to the root element for styling and identification.
|
|
Prop
|
Description
|
|---|---|
| badge |
Optional text to display as a badge (e.g., "Required", "Optional").
|
| aside |
Text displayed after the label and styled as a badge.
|
| trailing |
Optional text to display at the end of the label.
|
| srOnly |
Hides the label visually while keeping it accessible to screen readers.
|
|
Slot
|
Description
|
|---|---|
| children |
The label text content.
|
|
Prop
|
Description
|
|---|---|
| srOnly |
Hides the description visually while keeping it accessible to screen readers.
|
|
Slot
|
Description
|
|---|---|
| children |
The descriptive text content.
|
|
Prop
|
Description
|
|---|---|
| name |
The name of the field to display validation errors for.
|
| message |
Custom error message content (optional).
|
| icon |
The icon to display inline with the error message, a component or an element. Default: ExclamationTriangleIcon. Set to false to hide the icon.
|