You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While `Form.Root` shares the internal context required to make the `control` and field-inherited props optional, **it is highly recommended to pass them explicitly.**
69
+
70
+
Providing these props directly allows TypeScript to link your components to your specific form schema, enabling full type safety and robust auto-completion for every field path. Note that while sub-components can inherit the name from their parent `Form.Field`, the field itself always requires a `name` prop to function.
71
+
72
+
```tsx
73
+
// ✅ Recommended: schema-aware name prop
74
+
<Form.Fieldcontrol={form.control}name="email">
75
+
<Form.Label>Email</Form.Label>
76
+
<Form.Input />
77
+
</Form.Field>
78
+
```
79
+
80
+
```tsx
81
+
// ⚠️ Optional: "name" falls back to generic string
82
+
<Form.Fieldname="email">
83
+
<Form.Label>Email</Form.Label>
84
+
<Form.Input />
85
+
</Form.Field>
86
+
```
87
+
88
+
## Controlled Components
89
+
90
+
To integrate third-party components that don't expose a native `ref` (such as a Combobox or Switch), use the controlled component variants. These wrap React Hook Form's `Controller` while remaining fully integrated with the form's accessibility and error handling system.
91
+
92
+
### Form.FieldBoundController
93
+
94
+
This is the recommended approach for most controlled components. It must be nested within a `Form.Field`, which allows it to automatically bind to the parent's `name` and `control`.
Use this variant if you need a standalone controller that doesn't require a parent `Form.Field`. It provides its own field context, making it useful for specialized layouts or direct usage under `Form.Root`.
111
+
112
+
```tsx
113
+
<Form.FieldWithController
114
+
control={form.control}
115
+
name="notifications"
116
+
render={({ field }) => <Switchchecked={field.value}onCheckedChange={field.onChange} />}
117
+
/>
118
+
```
119
+
66
120
## Reactive State
67
121
68
122
To avoid unnecessary full-form re-renders, use the `Form.Watch` and `Form.StateSubscribe` components. They isolate re-renders by subscribing only to the specific field values or form states you need.
0 commit comments