# Field Connect a visible label, help text and validation feedback to an input without a form engine. [Interactive guide](/docs/components/field) · Forge 3.2.0 Use the API for your installed version. Run `npx --no-install wss3-forge api --json` inside the project. ## Implementation guidance ### When to use it Use Field when you need accessible field structure and feedback around an existing control. ### How to compose it Connect label, control and feedback with matching identifiers or forward the supplied control props. Group related controls with FieldSet and FieldLegend. ### What to verify Verify the invalid state announces the current error and preserves the label connection when feedback changes. ## Usage ```tsx import { Field, FieldSet, FieldLegend, FieldGroup, FieldContent, FieldLabel, FieldTitle, FieldDescription, FieldError, FieldSeparator } from 'wss3-forge' ``` - Compose FieldLabel, FieldContent and a control inside Field for custom layouts. Connect labels with htmlFor and id, descriptions with aria-describedby, and invalid controls with aria-invalid. - For validation libraries, pass their issue array to FieldError.errors. Repeated messages are merged and multiple messages render as a list. - Pass a single labelable control that forwards id, required and ARIA attributes. Use the render function when the control needs these props passed explicitly. - Pass the current error after validation. The label stays attached and the error is linked to the input alongside any help text. - Use FieldSet and FieldLegend for controls that share a question. FieldGroup supplies consistent spacing between fields. - FieldDescription and FieldError can render independent feedback. When placing one outside Field, link its id explicitly. ```tsx ``` ## Runnable examples ### Payment form ```tsx import { useId, useState, type ComponentType, type ReactNode } from 'react' import { Button, Checkbox, Direction, Grid, HStack, Input, Select, Textarea, VStack } from 'wss3-forge' import { Field, FieldDescription, FieldGroup, FieldLabel as RootLabel, FieldLegend, FieldSeparator, FieldSet } from 'wss3-forge' type LabelSlot = { FieldLabel?: ComponentType<{ htmlFor?: string; children: ReactNode }> } function PaymentForm({ rtl = false, FieldLabel = RootLabel }: LabelSlot & { rtl?: boolean }) { const prefix = useId() const [sameAddress, setSameAddress] = useState(true) const [month, setMonth] = useState('') const [year, setYear] = useState('') const firstYear = new Date().getFullYear() const [submitted, setSubmitted] = useState(false) function reset() { setSubmitted(false) setSameAddress(true) setMonth('') setYear('') } return
{ event.preventDefault(); setSubmitted(true) }} onChange={() => setSubmitted(false)} onReset={reset}>
{rtl ? 'طريقة الدفع' : 'Payment method'} {rtl ? 'استخدم بيانات تجريبية لطلب الطباعة.' : 'Enter sample payment details for this print order.'} {rtl ? 'الاسم على البطاقة' : 'Name on card'} { setYear(value); setSubmitted(false) }} options={Array.from({ length: 8 }, (_, i) => String(firstYear + i))} />
{rtl ? 'عنوان الفوترة' : 'Billing address'} {!sameAddress && }