Zephora UI

Form

Form

Form layout wrapper plus FormField, a labelled row that auto-wires id, name, aria-describedby, aria-invalid and aria-required into its child control and renders label, help and error text.

Import

import { Form, FormField, useFormField } from "@zephora/react";

Examples

Vertical layout

FormField connects the label and messages to the control automatically.

We never share your email.

Error state

Setting error renders a role="alert" message and marks the control aria-invalid.

Horizontal layout

`layout="horizontal"` puts labels beside their controls.

API

Form props

PropTypeDefaultDescription
layout"vertical" | "horizontal""vertical"Field arrangement, inherited by every FormField inside.
gapnumber | stringGap between fields. Numbers are treated as px, strings as CSS lengths.
unstyledbooleanfalseHeadless mode — drops Zephora classes so your own CSS can style it.
…restFormHTMLAttributes<HTMLFormElement>All native form props (onSubmit, action…) are forwarded.

FormField props

PropTypeDefaultDescription
namestringName injected into the child control.
labelReactNodeLabel text, wired to the control with htmlFor.
helpReactNodeHelp text announced via aria-describedby.
errorReactNodeError message (role="alert"); also sets aria-invalid on the control.
requiredbooleanfalseMarks the control as required (aria-required) and shows an asterisk.
childrenReactNodeA single control element; it receives id, name and aria wiring via cloneElement.
unstyledbooleanfalseHeadless mode — drops Zephora classes so your own CSS can style it.
…restHTMLAttributes<HTMLDivElement>Forwarded to the field wrapper element.

useFormField props

PropTypeDefaultDescription
useFormField()FormFieldContextValue | nullHook for custom controls: returns the enclosing FormField's { id, helpId, errorId, invalid, required, name } or null outside a FormField.