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

[Box] Remove render prop #26113

Merged
merged 3 commits into from
May 4, 2021
Merged

Conversation

m4theushw
Copy link
Member

@m4theushw m4theushw commented May 4, 2021

Breaking changes

  • [Box] Remove the render prop because its behavior can be obtained using the sx prop directly on the child if it's a Material-UI component. For non-Material-UI components use the sx prop in conjunction with the component prop:

    -<Box sx={{ border: '1px dashed grey' }}>
    -  {(props) => <Button {...props}>Save</Button>}
    -</Box>
    +<Button sx={{ border: '1px dashed grey' }}>Save</Button>
    -<Box sx={{ border: '1px dashed grey' }}>
    -  {(props) => <button {...props}>Save</button>}
    -</Box>
    +<Box component="button" sx={{ border: '1px dashed grey' }}>Save</Box>

Part of #20012.
A follow up of #26031. #26031 (comment)

https://deploy-preview-26113--material-ui.netlify.app/components/box

@mui-pr-bot
Copy link

mui-pr-bot commented May 4, 2021

Details of bundle changes

Generated by 🚫 dangerJS against 6e2158d

@mnajdova
Copy link
Member

mnajdova commented May 4, 2021

Let’s also add in the breaking changes of how we can also apply this on the intrinsic elements, for example using the component prop:

-<Box sx={{ border: '1px dashed grey' }}>
-  {(props) => <button {...props}>Save</button>}
-</Box>
+<Box component='button' sx={{ border: '1px dashed grey' }} />

To workaround the problem, you have two options:

1. Use the [`sx`](/system/basics/#the-sx-prop) prop directly on the child if it is Material-UI component
To workaround the problem, you can use the [`sx`](/system/basics/#the-sx-prop) prop directly on the child if it is a Material-UI component.
Copy link
Member

@mnajdova mnajdova May 4, 2021

Choose a reason for hiding this comment

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

I would here also mention the component prop for the non Material-UI components.

@oliviertassinari
Copy link
Member

oliviertassinari commented May 4, 2021

At some point, I have wondered if it wouldn't make sense to keep the render prop API for when customizing third-party components, but forcing the developer down the styled() API is probably better, so all good from my end (and we have #23220).


On a different note, the documentation page of the Box could maybe be improved. What about the following proposal?

  1. In /system/basics/#2-box, describe how to create its own Box component without the core, but @material-ui/styled-engine. This would be for the audience that doesn't want to use the core components.
  2. In /system/basics/#3-custom-components, describe how it create its own styled function with the sx prop and @material-ui/styled-engine. This would be for the audience that doesn't want to use the core components.
  3. In /components/box/:

@m4theushw
Copy link
Member Author

m4theushw commented May 4, 2021

describe the component prop, it's not explained anywhere

It's explained in "Overriding Material-UI components". I agree that this section should be removed or converted to describe how to use the component prop to override non-Material-UI components. For core components, we should encourage to use directly the sx prop, maybe with a warning at the beginning of the page.

These small updates in the docs I'll do in another PR.

Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

👍

@m4theushw m4theushw merged commit 2936ff7 into mui:next May 4, 2021
@m4theushw m4theushw deleted the box-remove-render-prop branch May 4, 2021 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants