Can't use Box to do one off style overrides of external components when there are props collisions
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 99.1k
- Forks
- 32.5k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 106
Description
Duplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Steps to reproduce 🕹
Link to live example:
https://codesandbox.io/s/resizablebox-prop-collision-cedc3v?file=/src/App.tsx
Current behavior 😯
using
<Box component={MyBox /* MyBox does use the className prop */}
myprop={42 /* myprop is some custom prop of MyBox*/}
sx={ /*using sx to get theme values, or to compose styles, or for consistency.. */
theme => ({backgroundColor: theme.foo.bar})
}
>
...
</Box>
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..
const MyBoxSx = styled(MyBox)({}); /* MyBox does use the className prop */
<MyBoxSx
myprop={42 /* myprop is some custom prop of MyBox*/}
sx={ /*using sx to get theme values, or to compose styles, or for consistency.. */
theme => ({backgroundColor: theme.foo.bar})
}
Your environment 🌎
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the CodeSandbox example in src/App.tsx and reproduce the Box usage with ResizableBox, comparing the working resizeHandle prop with the colliding width prop. The change is complete when arbitrary external component props such as width or border pass through while sx styling continues to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100