Skip to content

Commit b987e62

Browse files
committed
update disable-clear
1 parent d72a583 commit b987e62

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

docs/SimpleFormIterator.md

+14-5
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ const OrderEdit = () => (
7070
| Prop | Required | Type | Default | Description |
7171
|----------|----------|----------------|-----------------------|-------------------------------------|
7272
| `addButton` | Optional | `ReactElement` | - | Component to render for the add button |
73-
| `clearButton` | Optional | `boolean` | `true` | When `false`, the user cannot clear the array |
7473
| `children` | Optional | `ReactElement` | - | List of inputs to display for each row |
7574
| `className` | Optional | `string` | - | Applied to the root element (`<ul>`) |
7675
| `disableAdd` | Optional | `boolean` | `false` | When true, the user cannot add new rows |
76+
| `disableClear` | Optional | `boolean` | `false` | When true, the user cannot clear the array |
7777
| `disableRemove` | Optional | `boolean` | `false` | When true, the user cannot remove rows |
7878
| `disableReordering` | Optional | `boolean` | `false` | When true, the user cannot reorder rows |
7979
| `fullWidth` | Optional | `boolean` | `false` | Set to true to push the actions to the right |
@@ -95,10 +95,6 @@ This prop lets you pass a custom element to replace the default Add button.
9595
</SimpleFormIterator>
9696
```
9797

98-
## `clearButton`
99-
100-
This prop lets you pass a custom element to replace the default "Clear the list" button
101-
10298
## `children`
10399

104100
A list of Input elements, that will be rendered on each row.
@@ -202,6 +198,19 @@ When true, the Add button isn't rendered, so users cannot add new rows.
202198
</SimpleFormIterator>
203199
```
204200

201+
## `disableClear`
202+
203+
When true, the array clear button isn't rendered, so the user cannot clear the array.
204+
205+
```jsx
206+
<SimpleFormIterator disableClear>
207+
<TextInput source="name" />
208+
<NumberInput source="price" />
209+
<NumberInput source="quantity" />
210+
</SimpleFormIterator>
211+
```
212+
213+
205214
## `disableRemove`
206215

207216
When true, the Remove buttons aren't rendered, so users cannot remove existing rows.

packages/ra-ui-materialui/src/input/ArrayInput/SimpleFormIterator.stories.tsx

+15-15
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ export const DisableAdd = () => (
122122
</AdminContext>
123123
);
124124

125+
export const DisableClear = () => (
126+
<AdminContext dataProvider={dataProvider}>
127+
<Edit resource="books" id="1">
128+
<SimpleForm>
129+
<ArrayInput source="authors">
130+
<SimpleFormIterator disableClear>
131+
<TextInput source="name" />
132+
<TextInput source="role" />
133+
</SimpleFormIterator>
134+
</ArrayInput>
135+
</SimpleForm>
136+
</Edit>
137+
</AdminContext>
138+
);
139+
125140
export const DisableRemove = () => (
126141
<AdminContext dataProvider={dataProvider}>
127142
<Edit resource="books" id="1">
@@ -177,18 +192,3 @@ export const Sx = () => (
177192
</Edit>
178193
</AdminContext>
179194
);
180-
181-
export const DisableClearButton = () => (
182-
<AdminContext dataProvider={dataProvider}>
183-
<Edit resource="books" id="1">
184-
<SimpleForm>
185-
<ArrayInput source="authors">
186-
<SimpleFormIterator clearButton={false}>
187-
<TextInput source="name" />
188-
<TextInput source="role" />
189-
</SimpleFormIterator>
190-
</ArrayInput>
191-
</SimpleForm>
192-
</Edit>
193-
</AdminContext>
194-
);

packages/ra-ui-materialui/src/input/ArrayInput/SimpleFormIterator.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ export const SimpleFormIterator = (props: SimpleFormIteratorProps) => {
4444
addButton = <DefaultAddItemButton />,
4545
removeButton = <DefaultRemoveItemButton />,
4646
reOrderButtons = <DefaultReOrderButtons />,
47-
clearButton = true,
4847
children,
4948
className,
5049
resource,
5150
source,
5251
disabled,
5352
disableAdd,
53+
disableClear,
5454
disableRemove,
5555
disableReordering,
5656
inline,
@@ -195,7 +195,7 @@ export const SimpleFormIterator = (props: SimpleFormIteratorProps) => {
195195
),
196196
})}
197197
{fields.length > 0 &&
198-
clearButton &&
198+
!disableClear &&
199199
!disableRemove && (
200200
<>
201201
<Confirm
@@ -259,11 +259,11 @@ type GetItemLabelFunc = (index: number) => string | ReactElement;
259259

260260
export interface SimpleFormIteratorProps extends Partial<UseFieldArrayReturn> {
261261
addButton?: ReactElement;
262-
clearButton?: boolean;
263262
children?: ReactNode;
264263
className?: string;
265264
disabled?: boolean;
266265
disableAdd?: boolean;
266+
disableClear?: boolean;
267267
disableRemove?: boolean | DisableRemoveFunction;
268268
disableReordering?: boolean;
269269
fullWidth?: boolean;

0 commit comments

Comments
 (0)