Skip to content

Commit

Permalink
Merge pull request #3984 from marmelab/variant-prop-fields
Browse files Browse the repository at this point in the history
[RFR] Fix Field in form does not like the variant prop
  • Loading branch information
djhi authored Nov 14, 2019
2 parents 26bde6d + e327b83 commit c7779bb
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/CreateEdit.md
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,23 @@ export const PostEdit = (props) => (
);
```
**Tip**: If your form contains not only Inputs but also Fields, the injection of the `variant` property to the form children will cause a React warning. You'll need to wrap every Field component in another component to ignore the injected `variant` prop, as follows:
```diff
+const TextFieldInForm = ({ variant, ...props }) => <TextField {...props} />;
+TextFieldInForm.defaultProps = TextField.defaultProps;

```jsx
export const PostEdit = (props) => (
<Edit {...props}>
<SimpleForm variant="standard">
- <TextField source="title" />
+ <TextFieldInForm source="title" />
</SimpleForm>
</Edit>
);
```

## Margin

By default, react-admin input components use the Material Design "dense" margin. If you want to use the "normal" or "none" margins, you can either set the `margin` prop on each Input component individually, or set the `margin` prop directly on the Form component. In that case, the Form component will transmit the `margin` to each Input.
Expand Down

0 comments on commit c7779bb

Please sign in to comment.