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
Copy file name to clipboardExpand all lines: docs/SimpleFormIterator.md
+33-15Lines changed: 33 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,17 +77,19 @@ const OrderEdit = () => (
77
77
|`children`| Optional |`ReactElement`| - | List of inputs to display for each row |
78
78
|`className`| Optional |`string`| - | Applied to the root element (`<ul>`) |
79
79
|`disableAdd`| Optional |`boolean`|`false`| When true, the user cannot add new rows |
80
+
|`disableAutoFocus`| Optional |`boolean`|`false`| Prevent focusing the first input when adding a new row |
80
81
|`disableClear`| Optional |`boolean`|`false`| When true, the user cannot clear the array |
82
+
|`disabled`| Optional |`boolean`|`false`| If true, all buttons are disabled. |
81
83
|`disableRemove`| Optional |`boolean`|`false`| When true, the user cannot remove rows |
82
84
|`disableReordering`| Optional |`boolean`|`false`| When true, the user cannot reorder rows |
83
85
|`fullWidth`| Optional |`boolean`|`true`| Set to false to glue the actions to last input |
84
86
|`getItemLabel`| Optional |`function`|`x => x`| Callback to render the label displayed in each row |
85
87
|`inline`| Optional |`boolean`|`false`| When true, inputs are put on the same line |
86
88
|`removeButton`| Optional |`ReactElement`| - | Component to render for the remove button |
87
89
|`reOrderButtons`| Optional |`ReactElement`| - | Component to render for the up / down button |
88
-
|`disabled`| Optional |`boolean`|`false`| If true, all buttons are disabled. |
89
90
|`sx`| Optional |`SxProps`| - | Material UI shortcut for defining custom styles |
90
91
92
+
91
93
## `addButton`
92
94
93
95
This prop lets you pass a custom element to replace the default Add button.
@@ -211,6 +213,23 @@ When true, the Add button isn't rendered, so users cannot add new rows.
211
213
</SimpleFormIterator>
212
214
```
213
215
216
+
## `disableAutoFocus`
217
+
218
+
By default, `<SimpleFormIterator>` focuses the first input of a newly added row.
219
+
This behavior comes from `react-hook-form`'s [`useFieldArray`](https://react-hook-form.com/docs/usefieldarray) `append()` method.
220
+
221
+
You can disable this behavior by setting the `disableAutoFocus` prop.
222
+
223
+
```jsx
224
+
<ArrayInput source="items">
225
+
<SimpleFormIterator disableAutoFocus>
226
+
<TextInput source="name"/>
227
+
<NumberInput source="price"/>
228
+
<NumberInput source="quantity"/>
229
+
</SimpleFormIterator>
230
+
</ArrayInput>
231
+
```
232
+
214
233
## `disableClear`
215
234
216
235
When true, the array clear button isn't rendered, so the user cannot clear the array.
@@ -223,6 +242,19 @@ When true, the array clear button isn't rendered, so the user cannot clear the a
223
242
</SimpleFormIterator>
224
243
```
225
244
245
+
## `disabled`
246
+
247
+
The `disabled` prop set to true makes the children input not mutable, focusable, or even submitted with the form.
248
+
249
+
```jsx
250
+
<SimpleFormIterator disabled>
251
+
<TextInput source="name"/>
252
+
<NumberInput source="price"/>
253
+
<NumberInput source="quantity"/>
254
+
</SimpleFormIterator>
255
+
```
256
+
257
+
Contrary to read-only controls, disabled controls can not receive focus and are not submitted with the form.
226
258
227
259
## `disableRemove`
228
260
@@ -401,20 +433,6 @@ The `readOnly` prop set to true makes the children input not mutable, meaning th
401
433
402
434
Contrary to disabled controls, read-only controls are still focusable and are submitted with the form.
403
435
404
-
## `disabled`
405
-
406
-
The `disabled` prop set to true makes the children input not mutable, focusable, or even submitted with the form.
407
-
408
-
```jsx
409
-
<SimpleFormIterator disabled>
410
-
<TextInput source="name"/>
411
-
<NumberInput source="price"/>
412
-
<NumberInput source="quantity"/>
413
-
</SimpleFormIterator>
414
-
```
415
-
416
-
Contrary to read-only controls, disabled controls can not receive focus and are not submitted with the form.
417
-
418
436
## `sx`
419
437
420
438
You can override the style of the root element (a `<div>` element) as well as those of the inner components thanks to the `sx` property (see [the `sx` documentation](./SX.md) for syntax and examples).
|`children`| Optional |`ReactNode`| - | List of inputs to display for each array item |
71
+
|`disableAutoFocus`| Optional |`boolean`|`false`| Prevent focusing the first input when adding a new item |
72
+
73
+
## `disableAutoFocus`
74
+
75
+
When true, will pass `{ shouldFocus: false }` to `react-hook-form`'s [`useFieldArray`](https://react-hook-form.com/docs/usefieldarray)`append()` method when adding a new item, preventing the first input of the newly added item from being focused automatically.
0 commit comments