Skip to content
THE COMPONENT LIBRARY
Skip to content

Component reference

Form

Typed values, validation and submit state with useForm.

Preview

Live preview

Changes apply to this preview only.

Loading the interactive example?

Width adapts to the available space

More examples

Different configurations and compositions using the real Pimolu API. Each preview runs independently and follows the site appearance.

Validation and async submit

validate returns a map of messages. When it finds one, onSubmit is never called; as soon as a field changes, its message is cleared.

Open preview

Prefill, reset and inspect

setValues merges several fields at once, reset returns to defaultValues and clears every error. values is a plain object you can read at any time.

Open preview

Native constraints

noValidate defaults to true so the component owns the error UI. Set it to false to let the browser enforce required, type and pattern too.

Open preview

Usage

Create a flat defaultValues object and return field messages from validate to block submission. FormSubmit reflects isSubmitting; FormError belongs inside Form.

register reads native onChange values. For the styled Select, use form.values and form.setValue with onValueChange instead of relying on native onChange. Submission errors from a remote service remain your application's responsibility.

API reference

Generated from the public TypeScript declarations. Native HTML attributes are inherited where the component extends them; this reference includes Pimolu props and selected common native attributes.

UseFormOptions

Type source
UseFormOptions public API
NameTypeDefaultDescription
defaultValuesRequiredT—Initial values; also the values restored by `reset()`.
validateFormValidate<T> | undefined—Whole-form validation. Return a map of messages to block submit.
onSubmitFormSubmitHandler<T> | undefined—Called with the current values when the form is valid.
defaultValuesRequired

T

No default extracted.

Initial values; also the values restored by `reset()`.

validate

FormValidate<T> | undefined

No default extracted.

Whole-form validation. Return a map of messages to block submit.

onSubmit

FormSubmitHandler<T> | undefined

No default extracted.

Called with the current values when the form is valid.

PimoluFormRegistration

Type source
PimoluFormRegistration public API
NameTypeDefaultDescription
nameRequiredstring—Public Pimolu prop; see the source declaration for details.
valuestring | number | readonly string[] | undefined—Public Pimolu prop; see the source declaration for details.
checkedboolean | undefined—Public Pimolu prop; see the source declaration for details.
onChangeRequired(event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void—Public Pimolu prop; see the source declaration for details.
aria-invalidtrue | undefined—Public Pimolu prop; see the source declaration for details.
aria-describedbystring | undefined—Public Pimolu prop; see the source declaration for details.
nameRequired

string

No default extracted.

Public Pimolu prop; see the source declaration for details.

value

string | number | readonly string[] | undefined

No default extracted.

Public Pimolu prop; see the source declaration for details.

checked

boolean | undefined

No default extracted.

Public Pimolu prop; see the source declaration for details.

onChangeRequired

(event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void

No default extracted.

Public Pimolu prop; see the source declaration for details.

aria-invalid

true | undefined

No default extracted.

Public Pimolu prop; see the source declaration for details.

aria-describedby

string | undefined

No default extracted.

Public Pimolu prop; see the source declaration for details.

UseFormReturn

Type source
UseFormReturn public API
NameTypeDefaultDescription
valuesRequiredT—Current values, updated by `setValue` and `register`.
errorsRequiredPartial<Record<Extract<keyof T, string>, string>>—Current validation messages, keyed by field name.
isSubmittingRequiredboolean—True while an async `onSubmit` is pending.
formIdRequiredstring—Stable id prefix shared with `FormError`.
setValueRequired<K extends Extract<keyof T, string>>(name: K, value: T[K]) => void—Set one field and clear its error.
setValuesRequired(values: Partial<T>) => void—Merge several values and clear their errors.
setErrorRequired(name: Extract<keyof T, string>, message?: string) => void—Set or clear one field error programmatically.
clearErrorsRequired(name?: Extract<keyof T, string>) => void—Clear every error, or only one field.
registerRequired<K extends Extract<keyof T, string>>(name: K) => PimoluFormRegistration—Props that bind a native or Pimolu control to a field.
handleSubmitRequired(event?: FormEvent<HTMLFormElement>) => Promise<boolean>—Validate, then submit. Returns whether the form was valid.
resetRequired(nextValues?: Partial<T>) => void—Restore the initial values, or merge new ones.
valuesRequired

T

No default extracted.

Current values, updated by `setValue` and `register`.

errorsRequired

Partial<Record<Extract<keyof T, string>, string>>

No default extracted.

Current validation messages, keyed by field name.

isSubmittingRequired

boolean

No default extracted.

True while an async `onSubmit` is pending.

formIdRequired

string

No default extracted.

Stable id prefix shared with `FormError`.

setValueRequired

<K extends Extract<keyof T, string>>(name: K, value: T[K]) => void

No default extracted.

Set one field and clear its error.

setValuesRequired

(values: Partial<T>) => void

No default extracted.

Merge several values and clear their errors.

setErrorRequired

(name: Extract<keyof T, string>, message?: string) => void

No default extracted.

Set or clear one field error programmatically.

clearErrorsRequired

(name?: Extract<keyof T, string>) => void

No default extracted.

Clear every error, or only one field.

registerRequired

<K extends Extract<keyof T, string>>(name: K) => PimoluFormRegistration

No default extracted.

Props that bind a native or Pimolu control to a field.

handleSubmitRequired

(event?: FormEvent<HTMLFormElement>) => Promise<boolean>

No default extracted.

Validate, then submit. Returns whether the form was valid.

resetRequired

(nextValues?: Partial<T>) => void

No default extracted.

Restore the initial values, or merge new ones.

PimoluFormProps

Type source
PimoluFormProps public API
NameTypeDefaultDescription
formRequiredUseFormReturn<T>—The value returned by `useForm`.
noValidateboolean | undefinedtrueDisable the browser validation UI. Defaults to true.
childrenReactNode"Submit"Public Pimolu prop; see the source declaration for details.
onChangeChangeEventHandler<HTMLFormElement, Element> | undefined—Standard React/HTML attribute.
defaultValuestring | number | readonly string[] | undefined—Standard React/HTML attribute.
classNamestring | undefined—Standard React/HTML attribute.
styleCSSProperties | undefined—Standard React/HTML attribute.
aria-labelstring | undefined—Defines a string value that labels the current element.
onClickMouseEventHandler<HTMLFormElement> | undefined—Standard React/HTML attribute.
namestring | undefined—Standard React/HTML attribute.
formRequired

UseFormReturn<T>

No default extracted.

The value returned by `useForm`.

noValidate

boolean | undefined

Default: true

Disable the browser validation UI. Defaults to true.

children

ReactNode

Default: "Submit"

Public Pimolu prop; see the source declaration for details.

onChange

ChangeEventHandler<HTMLFormElement, Element> | undefined

No default extracted.

Standard React/HTML attribute.

defaultValue

string | number | readonly string[] | undefined

No default extracted.

Standard React/HTML attribute.

className

string | undefined

No default extracted.

Standard React/HTML attribute.

style

CSSProperties | undefined

No default extracted.

Standard React/HTML attribute.

aria-label

string | undefined

No default extracted.

Defines a string value that labels the current element.

onClick

MouseEventHandler<HTMLFormElement> | undefined

No default extracted.

Standard React/HTML attribute.

name

string | undefined

No default extracted.

Standard React/HTML attribute.

PimoluFormErrorProps

Type source
PimoluFormErrorProps public API
NameTypeDefaultDescription
nameRequiredstring—Registered field name.
classNamestring | undefined—Public Pimolu prop; see the source declaration for details.
nameRequired

string

No default extracted.

Registered field name.

className

string | undefined

No default extracted.

Public Pimolu prop; see the source declaration for details.

PimoluFormSubmitProps

Type source
PimoluFormSubmitProps public API
NameTypeDefaultDescription
childrenReactNode"Submit"Public Pimolu prop; see the source declaration for details.
onChangeChangeEventHandler<HTMLButtonElement, Element> | undefined—Standard React/HTML attribute.
defaultValuestring | number | readonly string[] | undefined—Standard React/HTML attribute.
classNamestring | undefined—Standard React/HTML attribute.
styleCSSProperties | undefined—Standard React/HTML attribute.
aria-labelstring | undefined—Defines a string value that labels the current element.
onClickMouseEventHandler<HTMLButtonElement> | undefined—Standard React/HTML attribute.
variant"primary" | "secondary" | "neutral" | "success" | "warning" | "danger" | undefined—Variant exposed by this component.
appearance"solid" | "soft" | "outline" | "ghost" | "link" | "dashed" | "glass" | "elevated" | "glow" | "text" | undefined—Visual treatment of the control or surface.
size"xs" | "sm" | "md" | "lg" | "xl" | "xxl" | undefined—Component size.
radius"sm" | "md" | "lg" | "none" | "full" | undefined—Corner-radius treatment.
disabledboolean | undefined—Standard React/HTML attribute.
namestring | undefined—Standard React/HTML attribute.
valuestring | number | readonly string[] | undefined—Standard React/HTML attribute.
startIconReactNode—Decorative content before the label or input.
endIconReactNode—Decorative content after the label or input.
fullWidthboolean | undefined—Use the available width of the parent.
iconOnlyboolean | undefined—Render an icon-only action. Provide an accessible name with aria-label.
children

ReactNode

Default: "Submit"

Public Pimolu prop; see the source declaration for details.

onChange

ChangeEventHandler<HTMLButtonElement, Element> | undefined

No default extracted.

Standard React/HTML attribute.

defaultValue

string | number | readonly string[] | undefined

No default extracted.

Standard React/HTML attribute.

className

string | undefined

No default extracted.

Standard React/HTML attribute.

style

CSSProperties | undefined

No default extracted.

Standard React/HTML attribute.

aria-label

string | undefined

No default extracted.

Defines a string value that labels the current element.

onClick

MouseEventHandler<HTMLButtonElement> | undefined

No default extracted.

Standard React/HTML attribute.

variant

"primary" | "secondary" | "neutral" | "success" | "warning" | "danger" | undefined

No default extracted.

Variant exposed by this component.

appearance

"solid" | "soft" | "outline" | "ghost" | "link" | "dashed" | "glass" | "elevated" | "glow" | "text" | undefined

No default extracted.

Visual treatment of the control or surface.

size

"xs" | "sm" | "md" | "lg" | "xl" | "xxl" | undefined

No default extracted.

Component size.

radius

"sm" | "md" | "lg" | "none" | "full" | undefined

No default extracted.

Corner-radius treatment.

disabled

boolean | undefined

No default extracted.

Standard React/HTML attribute.

name

string | undefined

No default extracted.

Standard React/HTML attribute.

value

string | number | readonly string[] | undefined

No default extracted.

Standard React/HTML attribute.

startIcon

ReactNode

No default extracted.

Decorative content before the label or input.

endIcon

ReactNode

No default extracted.

Decorative content after the label or input.

fullWidth

boolean | undefined

No default extracted.

Use the available width of the parent.

iconOnly

boolean | undefined

No default extracted.

Render an icon-only action. Provide an accessible name with aria-label.

Accessibility

  • Associate each field with a visible label and keep FormError beside it.
  • register connects error descriptions and invalid state. The current hook does not automatically move focus to the first invalid field; decide how your form should handle that.
Read the accessibility guide →