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/EditInDialogButton.md
+297-14
Original file line number
Diff line number
Diff line change
@@ -5,37 +5,47 @@ title: "EditInDialogButton"
5
5
6
6
# `<EditInDialogButton>`
7
7
8
-
This [Enterprise Edition](https://marmelab.com/ra-enterprise)<imgclass="icon"src="./img/premium.svg" /> component offers a way to open an `<Edit>` view inside a dialog, hence allowing to edit a record without leaving the current view.
9
-
10
-
It can be useful in case you want the ability to edit a record linked by a reference to the currently edited record, or if you have a nested `<Datagrid>` inside a `<Show>` or an `<Edit>` view.
8
+
This [Enterprise Edition](https://marmelab.com/ra-enterprise)<imgclass="icon"src="./img/premium.svg" /> component renders a button opening an `<Edit>` view inside a dialog, hence allowing to edit a record without leaving the current view.
It can be useful in case you want the ability to edit a record linked by a reference to the currently edited record, or if you have a nested `<Datagrid>` inside a `<Show>` or an `<Edit>` view.
17
+
18
18
Note that this component doesn't use routing, so it doesn't change the URL. It's therefore not possible to bookmark the edit dialog, or to link to it from another page. If you need that functionality, use [`<EditDialog>`](./EditDialog.md) instead.
19
19
20
20
## Usage
21
21
22
-
Put `<EditInDialogButton>` wherever you would put an `<EditButton>`, and use the same children as you would for an [`<Edit>`](./Edit.md) component (e.g. a `<SimpleForm>`):
22
+
First, install the `@react-admin/ra-form-layout` package:
23
+
24
+
```sh
25
+
npm install --save @react-admin/ra-form-layout
26
+
# or
27
+
yarn add @react-admin/ra-form-layout
28
+
```
29
+
30
+
**Tip**: [`ra-form-layout`](https://marmelab.com/ra-enterprise/modules/ra-form-layout#createindialogbutton-editindialogbutton-and-EditInDialogButton) is hosted in a private npm registry. You need to subscribe to one of the [Enterprise Edition](https://marmelab.com/ra-enterprise/) plans to access this package.
31
+
32
+
Then, put `<EditInDialogButton>` wherever you would put an `<EditButton>`, and use the same children as you would for an [`<Edit>`](./Edit.md) component (e.g. a `<SimpleForm>`):
By default, `<EditInDialogButton>` renders its child component even before the `dataProvider.getOne()` call returns. If you use `<SimpleForm>` or `<TabbedForm>`, this isn't a problem as these components only render when the record has been fetched. But if you use a custom child component that expects the record context to be defined, your component will throw an error.
143
+
144
+
To avoid this, set the `emptyWhileLoading` prop to `true`:
145
+
146
+
```jsx
147
+
constEditButton= () => (
148
+
<EditInDialogButton emptyWhileLoading>
149
+
...
150
+
</EditInDialogButton>
151
+
);
152
+
```
153
+
154
+
## `fullWidth`
155
+
156
+
By default, `<EditInDialogButton>` renders a [Material UI `<Dialog>`](https://mui.com/material-ui/react-dialog/#full-screen-dialogs) component that takes the width of its content.
157
+
158
+
You can make the dialog full width by setting the `fullWidth` prop to `true`:
159
+
160
+
```jsx
161
+
constEditButton= () => (
162
+
<EditInDialogButton fullWidth>
163
+
...
164
+
</EditInDialogButton>
165
+
);
166
+
```
167
+
168
+
In addition, you can set a dialog maximum width by using the `maxWidth` enumerable in combination with the `fullWidth` boolean. When the `fullWidth` prop is true, the dialog will adapt based on the `maxWidth` value.
169
+
170
+
```jsx
171
+
constEditButton= () => (
172
+
<EditInDialogButton fullWidth maxWidth="sm">
173
+
...
174
+
</EditInDialogButton>
175
+
);
176
+
```
177
+
178
+
## `icon`
179
+
180
+
The `icon` prop allows you to pass an icon to the button. It can be a MUI icon component, or a custom icon component.
181
+
182
+
```jsx
183
+
import { Edit } from'@mui/icons-material';
184
+
185
+
constEditButton= () => (
186
+
<EditInDialogButton icon={<Edit />}>
187
+
...
188
+
</EditInDialogButton>
189
+
);
190
+
```
191
+
192
+
## `id`
193
+
194
+
The `id` prop allows you to pass the record id to the `<EditInDialogButton>` component. If not provided, it will be deduced from the record context.
195
+
196
+
This is useful to link to a related record. For instance, the following button lets you show the author of a book:
By default, `<EditInDialogButton>` renders a `<Button>` component. If you want to display only an `<IconButton>`, set the `inline` prop to `true`:
212
+
213
+
```jsx
214
+
constEditButton= () => (
215
+
<EditInDialogButton inline>
216
+
...
217
+
</EditInDialogButton>
218
+
);
219
+
```
220
+
221
+
## `label`
222
+
223
+
The `label` prop allows you to pass a custom label to the button, instead of the default ("Edit"). It can be a string, or a React element.
224
+
225
+
```jsx
226
+
constEditButton= () => (
227
+
<EditInDialogButton label="Edit details">
228
+
...
229
+
</EditInDialogButton>
230
+
);
231
+
```
232
+
233
+
## `maxWidth`
234
+
235
+
The `maxWidth` prop allows you to set the max width of the dialog. It can be one of the following values: `xs`, `sm`, `md`, `lg`, `xl`, `false`. The default is `sm`.
236
+
237
+
For example, you can use that prop to make the dialog full width:
238
+
239
+
```jsx
240
+
constEditButton= () => (
241
+
<EditInDialogButton fullWidth maxWidth={false}>
242
+
...
243
+
</EditInDialogButton>
244
+
);
245
+
```
246
+
247
+
## `mutationOptions`
248
+
249
+
The `queryOptions` prop allows you to pass options to the `useMutation` hook.
250
+
251
+
This can be useful e.g. to pass [a custom `meta`](./Actions.md#meta-parameter) to the `dataProvider.update()` call.
*`inline`: set to true to display only a Material UI `<IconButton>` instead of the full `<Button>`. The label will still be available as a `<Tooltip>` though.
62
-
*`icon`: allows to override the default icon.
63
-
*`label`: allows to override the default button label. I18N is supported.
64
-
*`ButtonProps`: object containing props to pass to Material UI's `<Button>`.
65
-
* remaining props will be passed to the [`<EditDialog>`](./EditDialog.md) dialog component.
281
+
The `resource` prop allows you to pass the resource name to the `<EditInDialogButton>` component. If not provided, it will be deduced from the resource context.
66
282
67
-
Check out [the `ra-form-layout` documentation](https://marmelab.com/ra-enterprise/modules/ra-form-layout#createindialogbutton-editindialogbutton-and-showindialogbutton) for more details.
283
+
This is useful to link to a related record. For instance, the following button lets you show the author of a book:
If you use `<SimpleForm>` as child of `<EditInDialogButton>`, the default form toolbar includes a `<DeleteButton>`. And upon deletion, this button redirects to the current resource list. This is probably not what you want, so it's common to customize the form toolbar to disable the redirection after deletion:
0 commit comments