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

Ensure form children can override props #5895

Merged
merged 2 commits into from Feb 19, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/ra-ui-materialui/src/form/FormInput.tsx
Expand Up @@ -29,7 +29,9 @@ const FormInput = <RecordType extends Record | Omit<Record, 'id'> = Record>(
) => {
const { input, classes: classesOverride, ...rest } = props;
const classes = useStyles(props);
const { id, ...inputProps } = input ? input.props : { id: undefined };
const { id, className, ...inputProps } = input
? input.props
: { id: undefined, className: undefined };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using an empty object will do the trick. No need to assign "undefined" since things are already "undefined" in the empty object

Copy link
Contributor Author

@djhi djhi Feb 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeScript disagrees

return input ? (
<div
className={classnames(
Expand All @@ -49,10 +51,11 @@ const FormInput = <RecordType extends Record | Omit<Record, 'id'> = Record>(
{
[classes.input]: !input.props.fullWidth,
},
input.props.className
className
),
id: input.props.id || input.props.source,
...rest,
...inputProps,
})}
</Labeled>
) : (
Expand All @@ -61,10 +64,11 @@ const FormInput = <RecordType extends Record | Omit<Record, 'id'> = Record>(
{
[classes.input]: !input.props.fullWidth,
},
input.props.className
className
),
id: input.props.id || input.props.source,
...rest,
...inputProps,
})
)}
</div>
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/form/SimpleForm.spec.tsx
Expand Up @@ -59,7 +59,7 @@ describe('<SimpleForm />', () => {
<SaveContextProvider value={saveContextValue}>
<SideEffectContextProvider value={sideEffects}>
<SimpleForm submitOnEnter={false} toolbar={<Toolbar />}>
<div />
<TextInput source="name" />
</SimpleForm>
</SideEffectContextProvider>
</SaveContextProvider>
Expand All @@ -71,7 +71,7 @@ describe('<SimpleForm />', () => {
<SaveContextProvider value={saveContextValue}>
<SideEffectContextProvider value={sideEffects}>
<SimpleForm submitOnEnter toolbar={<Toolbar />}>
<div />
<TextInput source="name" />
</SimpleForm>
</SideEffectContextProvider>
</SaveContextProvider>
Expand Down