grommet: Box component "as" / "tag" prop not working as intended
it 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:
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 15 (7 by maintainers)
@ShimiSun @mirshko I ran into this issue today and found the explanation in an issue in the
styled-componentsrepo. https://github.com/styled-components/styled-components/issues/1981#issuecomment-419287003Here’s the diagram from that issue
The way the
Boxcomponent 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
tagprop 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-componentsrepo, 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
asprop (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 Grommetdocs 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 thisforwardAsprop.Came across this, and think that this issue may possibly be laid to rest from the introduction of
forwardedAsprop according to the last comment on the issue atstyled-components. https://github.com/styled-components/styled-components/issues/1981#issuecomment-548860710How the example from the sandbox would work now:
@josiahdahl Thank you for diving deep on this one, this is great info, and will help us get to the next step. Moving the label to ‘discussion’, so we can discuss in the team whether we would like to make the effort of supporting the current behavior on our codebase.