FormField
Basic
<FormField label="Name" />
Controlled
<FormField label="Name" value={value} inputRest={{ onInput: onInput }} />
Helper text
Set
helperText
to a string to render helper text above the form field.Your first and last name
<FormField label="Name" helperText="Your first and last name" />
Invalid
Set
invalid
to either true
or false
. Defaults to false
.<FormField label="Name" invalid />
Error text
When
invalid
is true
, set errorText
to a string to render error text above the form field. Invalid name
<FormField label="Name" invalid errorText="Invalid name" />
Helper and error text
You can include both helper and error text.
Your first and last name
Invalid name
<FormField
label="Name"
helperText="Your first and last name"
invalid
errorText="Invalid name"
/>
Required
Set
required
to true
and requiredIndicator
to either "text"
, "asterisk"
, or "none"
.See https://ux.stackexchange.com/q/840/39046 for a discussion.
<Stack class="gap-5">
<FormField
label="Name"
required
requiredIndicator="text"
/>
<FormField
label="Name"
required
requiredIndicator="asterisk"
/>
</Stack>
Optional
Set
required
to false
and optionalIndicator
to either "text"
, "asterisk"
, or "none"
.See https://ux.stackexchange.com/q/840/39046 for a discussion.
<Stack class="gap-5">
<FormField
label="Name"
optionalIndicator="text"
/>
<FormField
label="Name"
optionalIndicator="asterisk"
/>
</Stack>
Size
Set
size
to "sm"
, "md"
, or "lg"
. Defaults to "md"
.First and last name
First and last name
First and last name
<Stack class="gap-5">
<FormField
label="Name"
size="sm"
required
requiredIndicator="text"
helperText="First and last name"
/>
<FormField
label="Name"
size="md"
required
requiredIndicator="text"
helperText="First and last name"
/>
<FormField
label="Name"
size="lg"
required
requiredIndicator="text"
helperText="First and last name"
/>
</Stack>
Width
These examples use
class="w-14 max-w-full"
and class="w-10"
to set the width of the form field.<Stack class="gap-5">
<FormField
label="Name on card"
type="text"
class="w-14 max-w-full"
/>
<FormField
label="Card number"
type="text"
class="w-14 max-w-full"
/>
<FormField
label="Expiry date"
type="text"
class="w-10"
/>
<FormField
label="CVC"
type="text"
class="w-10"
/>
</Stack>
Type
type
usually gets passed to Input
. However, for some of the values a component other than Input
is used. See the examples in the following sections.RFUI's
Input
component wraps the native HTML input
and passes type
to input
, and so you could find the possible values documented here on MDN. If you are thinking of using number
, consider taking this approach instead.<Stack class="gap-5">
<FormField label="Name" type="text" />
<FormField label="Email" type="email" />
<FormField label="Age" type="number" />
<FormField label="Password" type="password" value="foobar" />
<FormField label="Birthday" type="date" />
<FormField label="Appointment" type="datetime-local" />
<FormField label="Bed time" type="time" />
<FormField label="Profile photo" type="file" />
<FormField label="Mood" type="range" />
<FormField label="Favorite color" type="color" />
</Stack>
Checkbox
If you pass
type="checkbox"
it will use RFUI's Checkbox
component instead of doing <Input type="checkbox" />
.<FormField label="Agreed" type="checkbox" />
Switch
If you pass
type="switch"
it will use RFUI's Switch
.<FormField label="Agreed" type="switch" />
PasswordInput
<FormField label="Password" type="rfui-password-input" value="foobar" />
Textarea
Note:
value
isn't passed as a prop; it's passed instead like this: <Textarea>{value}</Textarea>
<FormField label="Notes" type="textarea" />
RadioButtonGroup
To use
RadioButtonGroup
with FormField
set type
to "radio-button-group"
and use radioButtonGroupOptions
like so:<FormField
label="Plan"
type="radio-button-group"
name="plan"
radioButtonGroupOptions={[
{ value: "free", display: "Free" },
{ value: "basic", display: "Basic" },
{ value: "premium", display: "Premium" },
]}
/>
Select
<FormField
label="Country"
type="select"
selectOptions={[
{ value: "united-states", display: "United States" },
{ value: "france", display: "France" },
{ value: "japan", display: "Japan" },
]}
/>
Props
Prop | Required | Default | Type and notes |
---|---|---|---|
label | ✔ | - |
|
name | - | - |
|
value | - | - |
|
type | - | - |
|
required | - | false |
|
requiredIndicator | - | "none" |
See https://ux.stackexchange.com/q/840/39046 for a discussion. |
optionalIndicator | - | "none" |
See https://ux.stackexchange.com/q/840/39046 for a discussion. |
helperText | - | - |
|
size | - | "md" |
|
rounded | - | - |
Defaults to the value of the CSS variable --default-roundedness . See "Default roundedness". |
invalid | - | false |
|
errorText | - | - |
|
radioButtonGroupOptions | - | - |
This is to be used to be used to construct <input type="radio"> elements when you have type="radio-button-group" . |
selectOptions | - | - |
This is to be used to be used to construct <option> elements when you have type="select" . |
inputRest | - | - |
The structure of FormField is something like this:
inputRest gets passed like this:
|
textareaRest | - | - |
The structure of FormField when used with type="textarea" is something like this:
textareaRest gets passed like this:
|
radioButtonGroupRest | - | - |
The structure of FormField when used with type="radio-button-group" is something like this:
radioButtonGroupRest gets passed like this:
|
selectRest | - | - |
The structure of FormField when used with type="select" is something like this:
selectRest gets passed like this:
|
...rest | - | - |
See the docs for rest parameters. For FormField , you could pass anything you normally would pass to <div> because the return value looks something like this:
|