Box component "as" / "tag" prop not working as intended
See original GitHub issueit looks like the Box component is not using the as
prop as it should. it looks to still be relying on the tag
component to actually apply the styles.
using as
causes the box component to become the unstyled version of itself.
examples:
when using tag
it works as intended, however in the docs it says this prop is deprecated. it looks like in the code it is not used as it should be.
examples:
Issue Analytics
- State:
- Created 5 years ago
- Comments:15 (5 by maintainers)
Top Results From Across the Web
V4: Using 'as' prop on an extended styled component does not ...
Thus when you use the "as" prop with a styled() wrapper around a custom component, the custom component is no longer the thing...
Read more >React component is not accepting JSX Element as prop
The shorthand prop for "Box" component was passed a JSX element but this slot only supports string|number|object|array|ReactElements. import ...
Read more >Unknown Prop Warning - React
The unknown-prop warning will fire if you attempt to render a DOM element with a prop that is not recognized by React as...
Read more >How To Customize React Components with Props
In this tutorial, you'll create custom components by passing props to your component. Props are arguments that you provide to a JSX element....
Read more >Composition - Material UI - MUI
To solve this problem, we tag some of the components with a muiName static property when needed. You may, however, need to wrap...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ShimiSun @mirshko I ran into this issue today and found the explanation in an issue in the
styled-components
repo. https://github.com/styled-components/styled-components/issues/1981#issuecomment-419287003Here’s the diagram from that issue
The way the
Box
component is rendered follows the second path, which I’ve simplified below, as well as a minimal example to replicate the issue.The easiest solution I see is to use the
tag
prop for now, since I’m not experienced enough with the Grommet code base to recommend a more in-depth fix. Based on the responses from the issue in thestyled-components
repo, they’re not interested in fixing it, it’s a low priority, or it’s just how the library is supposed to work, all of which are their prerogative.That might be worth noting, but it would have to be added to all components that use the
as
prop (I think*), of which there are quite a few I think.I would actually love to see a tutorial added to the
getting started with Grommet
docs that explained in a best practice how to extend theming and use styled-components in general with Grommet. I know I would personally benefit greatly if someone were willing to contribute such a thing. That could include things like using thisforwardAs
prop.