Skip to content

Commit 74680dc

Browse files
authored
Merge pull request #7721 from marmelab/7712-can-not-use-sxon-tabbedform
Add sx prop to TabbedForm and improve doc
2 parents 3fd39fe + 1455830 commit 74680dc

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

docs/TabbedForm.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,20 @@ export const PostCreate = () => {
176176

177177
Pass an `sx` prop to customize the style of the main component and the underlying elements.
178178

179-
The most common usage is to limit the width of the form, to avoid long inputs on large screens:
180-
181179
{% raw %}
182180
```jsx
183181
export const PostCreate = () => (
184182
<Create>
185-
<TabbedForm sx={{ maxWidth: 600 }}>
183+
<TabbedForm sx={{ border: '1px solid red' }}>
186184
...
187185
</TabbedForm>
188186
</Create>
189187
);
190188
```
191189
{% endraw %}
192190

191+
**Tip:** If you want to customize the _content_ of the tabs instead, for example to limit the width of the form, you should rather add an `sx` prop to the [`<FormTab>` component](#formtab).
192+
193193
## `syncWithLocation`
194194

195195
When the user clicks on a tab header, react-admin changes the URL to enable the back button.

packages/ra-ui-materialui/src/form/TabbedForm.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from 'ra-core';
1717
import get from 'lodash/get';
1818

19-
import { TabbedFormView } from './TabbedFormView';
19+
import { TabbedFormView, TabbedFormViewProps } from './TabbedFormView';
2020
import { useFormRootPath } from './useFormRootPath';
2121

2222
/**
@@ -113,7 +113,8 @@ export interface TabbedFormProps
113113
Omit<
114114
HtmlHTMLAttributes<HTMLFormElement>,
115115
'defaultValue' | 'onSubmit' | 'children'
116-
> {
116+
>,
117+
Partial<TabbedFormViewProps> {
117118
children: ReactNode;
118119
className?: string;
119120
defaultValues?: any;

packages/ra-ui-materialui/src/form/TabbedFormView.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const TabbedFormView = (props: TabbedFormViewProps): ReactElement => {
3333
syncWithLocation = true,
3434
tabs = DefaultTabs,
3535
toolbar = DefaultToolbar,
36+
...rest
3637
} = props;
3738
const location = useLocation();
3839
const resolvedPath = useResolvedPath('');
@@ -58,7 +59,10 @@ export const TabbedFormView = (props: TabbedFormViewProps): ReactElement => {
5859
);
5960

6061
return (
61-
<Root className={clsx('tabbed-form', className)}>
62+
<Root
63+
className={clsx('tabbed-form', className)}
64+
{...sanitizeRestProps(rest)}
65+
>
6266
{syncWithLocation ? (
6367
<Routes>
6468
<Route path="/*" element={renderTabHeaders()} />
@@ -144,3 +148,5 @@ const Root = styled('div', {
144148
color: theme.palette.error.main,
145149
},
146150
}));
151+
152+
const sanitizeRestProps = ({ record, resource, ...rest }: any) => rest;

0 commit comments

Comments
 (0)