Replies: 10 comments
-
Here's a PoC implementation of how I would expect https://codesandbox.io/embed/tender-gould-3q05k?file=/src/App.js |
Beta Was this translation helpful? Give feedback.
-
Are there any known workarounds for this? I'm trying to get a |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
You're right, (thanks for looking out on this front 😄) I was hoping to just reuse the |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
Possibly related (raised by @smhutch): https://codesandbox.io/s/the-as-prop-f7um6?file=/src/App.tsx |
Beta Was this translation helpful? Give feedback.
-
@jjenzz nice proof of concept 👍👍 I think we should create a polymorphic api standard that would solve this issue and allow multiple polymorphic components to work together seamlessly. Check out #609. |
Beta Was this translation helpful? Give feedback.
-
Another person hit that issue when using radix + stitches: |
Beta Was this translation helpful? Give feedback.
-
I think I have the same problem here: https://codesandbox.io/s/cool-andras-9sqjx?file=/src/App.js |
Beta Was this translation helpful? Give feedback.
-
We can move this into a discussion. The interoperability of |
Beta Was this translation helpful? Give feedback.
-
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 🙏
Beta Was this translation helpful? Give feedback.
All reactions