import { Field } from "@senvenli/react/form";
export default function Example() {
return (
<Field label="Reminder" htmlFor="reminder-days" description="Days before the due date that we email the customer.">
<input id="reminder-days" type="range" min={1} max={14} defaultValue={3} className="block w-full" />
</Field>
);
}import {
Field,
FieldLabel,
FieldDescription,
FieldError,
} from "@senvenli/react/form";Examples
Around an input group
The label, hint and error reach the group's input, not its frame.import { Field, InputAddon, InputGroup, InputGroupInput } from "@senvenli/react/form";
export default function Example() {
return (
<Field label="Budget" htmlFor="budget" description="Monthly, before tax." errorMessage="Enter a budget of at least $50.">
<InputGroup>
<InputAddon position="start">$</InputAddon>
<InputGroupInput inputMode="decimal" defaultValue="20" />
<InputAddon position="end">USD</InputAddon>
</InputGroup>
</Field>
);
}With an error
The error replaces the hint and marks the control invalid; a library control draws that state itself.import { Field, Input } from "@senvenli/react/form";
export default function Example() {
return (
<Field label="Support line" isRequired errorMessage="Enter the full number with its area code: (415) 555-0132.">
<Input type="tel" name="support-phone" defaultCountry="US" suggestedCountries={["US", "CA", "GB"]} defaultValue="+1415555" />
</Field>
);
}Guidelines
When to use it
- Wrapping a control the library does not provide, so it matches the other fields.
Use something else when
- A text input is enough; it has the field row built in. Input
Accessibility
Built in
- Label, hint and error are linked to the control with htmlFor, aria-describedby and aria-invalid.
You provide
- A control with a matching
id, or a single child Field can give one to.
API reference
Field
| Prop | Type | Default | Description |
|---|---|---|---|
label | ReactNode | – | |
htmlFor | string | – | Control id for the label. Optional: when omitted, Field generates one and injects it onto a single-element child. Field is for a control the library does not provide (a native input, a third-party widget) and for |
errorMessage | ReactNode | – | What went wrong and what to do; shown under the control and announced. |
description | ReactNode | – | A line of help under the control (hidden while there is an error). |
isRequired | boolean | – | |
requiredClassName | string | – | Class for the required "*" asterisk. Defaults to the danger text token; a brand marketing form can override it without forking this component. |
childrenRequired | ReactNode | – | |
className | string | – |
labelReactNodehtmlForstringControl id for the label. Optional: when omitted, Field generates one and injects it onto a single-element child. Field is for a control the library does not provide (a native input, a third-party widget) and for
InputGroupwithInputGroupInput, which forwards it to its input. The library's own fields (TextField, Select…) carry their own label, hint and error, so they do not go inside a Field.errorMessageReactNodeWhat went wrong and what to do; shown under the control and announced.
descriptionReactNodeA line of help under the control (hidden while there is an error).
isRequiredbooleanrequiredClassNamestringClass for the required "*" asterisk. Defaults to the danger text token; a brand marketing form can override it without forking this component.
childrenRequiredReactNodeclassNamestring
FieldLabel
| Prop | Type | Default | Description |
|---|---|---|---|
childrenRequired | React.ReactNode | – | |
isRequired | boolean | – | Shows |
isOptional | boolean | – | Shows "(optional)" in the provider locale; use it when most fields of the form are required. |
childrenRequiredReact.ReactNodeisRequiredbooleanShows
*inds-text-danger(hidden from screen readers: the control isaria-required).isOptionalbooleanShows "(optional)" in the provider locale; use it when most fields of the form are required.
FieldDescription
| Prop | Type | Default | Description |
|---|---|---|---|
childrenRequired | React.ReactNode | – |
childrenRequiredReact.ReactNode
FieldError
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | – |
childrenReact.ReactNode