import { FormField } from "@pixxl-tools/components";
// In Server Components:
import { FormField } from "@pixxl-tools/components/server";| Prop | Type | Default | Description |
|---|---|---|---|
description | ReactNode | — | Help text, wired to the control's aria-describedby. |
error | ReactNode | — | Error message: marks the control aria-invalid and wires the message to aria-describedby and aria-errormessage. |
label | ReactNode | — | Visible label (also the accessible name). |
invalid | boolean | — | Mark the control invalid without a message (e.g. a message shown elsewhere). |
labelFor | string | generated and given to the control | Id of the control (default: generated and given to the control). |
required | boolean | — | Shows the label's asterisk and sets aria-required on the control. |
descriptionReactNode
Help text, wired to the control's aria-describedby.
errorReactNode
Error message: marks the control aria-invalid and wires the message to aria-describedby and aria-errormessage.
labelReactNode
Visible label (also the accessible name).
invalidboolean
Mark the control invalid without a message (e.g. a message shown elsewhere).
labelFordefault generated and given to the controlstring
Id of the control (default: generated and given to the control).
requiredboolean
Shows the label's asterisk and sets aria-required on the control.
Other props are passed to the root element (HTMLAttributes<HTMLDivElement>), including className, style, id and aria-* attributes.
Pixels, between 8 and 64.
const [width, setWidth] = useState<number | null>(16);
const error = width !== null && (width < 8 || width > 64) ? "Use 8 to 64." : undefined;
<FormField label="Width" description="Pixels, between 8 and 64." error={error}>
<NumberField value={width} onValueChange={setWidth} />
</FormField>