-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
Can't use Box to do one off style overrides of external components when there are props collisions #37254
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
Comments
Can you provide a proper reproduction in the CodeSandbox of the issue you are fixing? I see that the props are getting applied to the Box component in the KO example: <Box
component={ResizableBox}
sx={{
backgroundColor: (theme) =>
theme.palette.mode === "light" ? "gold" : "blue"
}}
width={50}
height={50}
>
<span>Contents</span>
</Box> |
Since the issue is missing key information and has been inactive for 7 days, it has been automatically closed. If you wish to see the issue reopened, please provide the missing information. |
Hi,
Here's a short video showing this: muisxpropsswallow-2023-06-22_09.21.15.mp4As I said earlier, this is because some "business" prop names of the external component collide with "system" props. Here it's width and height, but like I said, if it were a component representing a country, its props could be "flag" and "border" but border happens to collide with the css border prop. |
Thanks for opening an issue. This is an interesting use-case. The Box component's props include all the props of the system prop (sx) directly, as mentioned in the documentation. This is why external props with the same name as sx properties are overridden. To support sx in a custom component that is not part of MUI, you can follow the instructions provided in the following link: https://mui.com/system/getting-started/custom-components/#using-sx-with-custom-components. However, this also creates a intermediate component because of Link to CodeSandbox - https://codesandbox.io/s/resizablebox-prop-collision-forked-s7pf6x?file=/src/App.tsx. |
Hi @ZeeshanTamboli, Also, my goal was indeed to avoid |
There is no advantage in my example over yours. That was just another way to do this. I think your example showcasing empty object passed to
Note that this is only for "CSS" utility components like
How would we identify that other non-MUI components, such as Using |
From what I understand, the only alternative would have been to not have sx props as direct props in Box. I think I read somewhere in an another issue that (<Box component={ExtBox} sx={mystyles} {...myprops} />) // sets the classname but clashes on system names
(<Bix component={ExtBox} sx={mystyles} wrappedProps={myprops} />) // same without clash ? What are the downsides of this ? |
We could do this: (<Box component={ExtBox} sx={mystyles} wrappedProps={myprops} />) // same without clash ? Also take a look at the API tradeoff documentation. I added this issue to #34883 for tracking purposes. It might be related to another issue listed in #34883. |
Uh oh!
There was an error while loading. Please reload this page.
Duplicates
Latest version
Steps to reproduce 🕹
Link to live example:
https://codesandbox.io/s/resizablebox-prop-collision-cedc3v?file=/src/App.tsx
Current behavior 😯
using
works except if myExternalProp happens to be one of the system prop (it gets swallowed). As an exemple, imagine a CountryBox which take the flag and border props. flag works, but border collides with css borders. In the example, it's ResizableBox from 'react-resizable'. The 'resizeHandle' prop works but the 'width' prop doesn't.
Expected behavior 🤔
Should be able to use pass any props to the component, because system props should be in sx, not in props of Box
Context 🔦
I want to use the mui styling system (to have inheritence, composition, theme access, etc) to do a one off customization of a component accepting a className, without adding dom elements and using nested selectors.
One way to do it is to use styled but this requires creating an intermediate component..
Your environment 🌎
No response
The text was updated successfully, but these errors were encountered: