Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix <TabbedForm> ignores the sx prop #7721

Merged
merged 1 commit into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/TabbedForm.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,20 @@ export const PostCreate = () => {

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

The most common usage is to limit the width of the form, to avoid long inputs on large screens:

{% raw %}
```jsx
export const PostCreate = () => (
<Create>
<TabbedForm sx={{ maxWidth: 600 }}>
<TabbedForm sx={{ border: '1px solid red' }}>
...
</TabbedForm>
</Create>
);
```
{% endraw %}

**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).

## `syncWithLocation`

When the user clicks on a tab header, react-admin changes the URL to enable the back button.
Expand Down
5 changes: 3 additions & 2 deletions packages/ra-ui-materialui/src/form/TabbedForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from 'ra-core';
import get from 'lodash/get';

import { TabbedFormView } from './TabbedFormView';
import { TabbedFormView, TabbedFormViewProps } from './TabbedFormView';
import { useFormRootPath } from './useFormRootPath';

/**
Expand Down Expand Up @@ -113,7 +113,8 @@ export interface TabbedFormProps
Omit<
HtmlHTMLAttributes<HTMLFormElement>,
'defaultValue' | 'onSubmit' | 'children'
> {
>,
Partial<TabbedFormViewProps> {
children: ReactNode;
className?: string;
defaultValues?: any;
Expand Down
8 changes: 7 additions & 1 deletion packages/ra-ui-materialui/src/form/TabbedFormView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const TabbedFormView = (props: TabbedFormViewProps): ReactElement => {
syncWithLocation = true,
tabs = DefaultTabs,
toolbar = DefaultToolbar,
...rest
} = props;
const location = useLocation();
const resolvedPath = useResolvedPath('');
Expand All @@ -58,7 +59,10 @@ export const TabbedFormView = (props: TabbedFormViewProps): ReactElement => {
);

return (
<Root className={clsx('tabbed-form', className)}>
<Root
className={clsx('tabbed-form', className)}
{...sanitizeRestProps(rest)}
>
{syncWithLocation ? (
<Routes>
<Route path="/*" element={renderTabHeaders()} />
Expand Down Expand Up @@ -144,3 +148,5 @@ const Root = styled('div', {
color: theme.palette.error.main,
},
}));

const sanitizeRestProps = ({ record, resource, ...rest }: any) => rest;