# FormField

> Wraps a control with a label, help/error text and id wiring, so a screen reader gets the full picture without manual aria plumbing.

- Package: `fancy-ui-react` (React 18/19 + Tailwind CSS v4)
- Category: Forms
- Tags: form, field, label, validation, accessibility, compound
- Dependencies: label
- Types: `FormFieldProps`
- Docs: https://fancy-ui.rama.app/docs/components/form-field
- Source: https://github.com/RamaHerbin/fancy-ui/tree/main/react/src/components/form-field

## Import

```tsx
import { FormField } from 'fancy-ui-react';
```

Setup (once per project): `npm install fancy-ui-react`, then put these lines in your main CSS file (the stylesheet import goes right after `@import "tailwindcss";`):

```css
@import "tailwindcss";
@import "fancy-ui-react/tailwind.css";
```

and import the component styles once in the app entry: `import "fancy-ui-react/styles.css";`. Full guide: https://fancy-ui.rama.app/llms.txt

The names below are the ones to write in React; when one differs from the Svelte name, the Svelte name follows in parentheses. `class` becomes `className`, a callback takes the name the React port declares (`onclick` becomes `onClick`), snippets become `ReactNode` props (render functions when they take arguments) and the default snippet is `children`. Divergences: https://github.com/RamaHerbin/fancy-ui/tree/main/react#divergences-from-the-svelte-api

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `label` | `string` | — | Label text — the common case. For custom label markup, render a Label in children instead |
| `description` | `string` | — | Help text under the control, replaced by error while the field is invalid |
| `error` | `string` | — | Error text. Setting it marks the field invalid and replaces the help text |
| `valid` | `boolean` | `false` | Decorative checkmark next to the help text; error always wins if both are set |
| `required` | `boolean` | `false` | Marks the field required: the label gets an asterisk, the control gets aria-required |
| `disabled` | `boolean` | `false` | Disables the field: reaches the wrapped control through context |
| `id` | `string` | — | Opts out of the generated id. description/error ids are suffixes of this same value |
| `className` (Svelte `class`) | `string` | — | Additional CSS classes, merged onto the root |
| `ref` | `HTMLDivElement \| null` | `null` | Bindable reference to the root element |

## Node props

| Prop | Description |
| --- | --- |
| `children` | The control |

## Example

```tsx
import { FormField, Input } from "fancy-ui-react";

export function FormFieldExample() {
	return (
		<FormField label="Email" description="We'll only use this to send your receipt.">
			<Input type="email" placeholder="you@example.com" />
		</FormField>
	);
}
```
