-
Notifications
You must be signed in to change notification settings - Fork 257
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
How to handle as
prop on styled(Component)
components
#448
Comments
Here's a PoC implementation of how I would expect https://codesandbox.io/embed/tender-gould-3q05k?file=/src/App.js |
Are there any known workarounds for this? I'm trying to get a |
EDIT: I've updated the sandbox and code snippet here with the correct example. My bad 😅 I believe the solution is to use the Primitive const Tab = React.forwardRef((props, forwardedRef) => (
<TabsPrimitive.Tab {...props} ref={forwardedRef} as={StyledTab} />
));
const StyledTab = styled("div", { color: "red" }); https://codesandbox.io/s/strange-waterfall-to6fu On a side note, I'm curious why you are converting a tab to a link? 😛 That sounds like you might be breaking accessibility there. The tab pattern is specifically for controlling display of content on the current page (not for navigation). If you're using the |
You're right, (thanks for looking out on this front 😄) I was hoping to just reuse the |
Just want to leave a not here that this was raised again as an issue in our primitives Discord: https://discord.com/channels/752614004387610674/803656530259738674/844509767187300422 https://codesandbox.io/s/immutable-cloud-jsh7o?file=/src/App.js |
Possibly related (raised by @smhutch): https://codesandbox.io/s/the-as-prop-f7um6?file=/src/App.tsx |
Another person hit that issue when using radix + stitches: |
I think I have the same problem here: https://codesandbox.io/s/cool-andras-9sqjx?file=/src/App.js |
We can move this into a discussion. The interoperability of |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Is your feature request related to a problem? Please describe.
What I am about to describe is something I have found confusing with
styled-components
and also exists institches
and we had someone report this as a bug in our Primitives Discord channel over the weekend.They tried something equivalent to the following:
A working example of the above code: https://codesandbox.io/s/xenodochial-oskar-ywq1z?file=/src/App.js:43-221
When doing this, the expectation was that
Item
would become abutton
withcolor: red; fontSize: 16px
styles but also maintain thedata-radix-primitive
attribute andPrimitive
functionality. That is not the case.The
as
prop will replace the component passed tostyled()
entirely with the component passed in theas
prop. This tends not to be expected but also seems a bit of an issue for us specifically given that we're advocating this is how people would style Primitives while maintaining theas
prop for use in their application.Describe the solution you'd like
I'm not raising as a bug because honestly, I'm not sure how this should behave.
It behaves the same with
styled-component
s, but you will see that they also provide aforwardedAs
prop to achieve what we expect: https://codesandbox.io/s/recursing-zhukovsky-qvkow?file=/src/App.jsMy expectation is that it would behave the same as
styled-components
but I've never been keen on theforwardedAs
prop. It might be the only way though.Describe alternatives you've considered
Hoping the team might have some ideas 🙏
The text was updated successfully, but these errors were encountered: