Replies: 3 comments 1 reply
-
I think we can control this via config or via a custom opt-out method as you mentioned Alternitevly, another solution would be to only omit variant props if the styled component wasn't extending other components: // Here we omit variant props:
const Test = styled.div({variants: {variant: {red: {}}}})
// Here we dont omit variant props and omiting variants becomes SomeOtherComponent's responsibility:
const Test = styled(SomeOtherComponent, {variants: {variant: {red: {}}}}) |
Beta Was this translation helpful? Give feedback.
-
Just a point of clarity, this isn’t actually an implementation detail but a part of the public API.
Definitely agree with this. I feel like Emotion struggled with this for years and never came up with a really great solution. @hadihallak I kind of like the idea of handling this via config. I think this issue will pop up from time to time but I can't imagine it being so frequent that the config gets out of hand. |
Beta Was this translation helpful? Give feedback.
-
Hi @peduarte, first of all thank you to you and your for this amazing library. I found this discussion while looking for a solution as to why my props are not being preserved in my component when the prop is also a variant. Looks like they're being stripped as part of sanitizing the html output, removing potentially invalid attributes. And that's really the keyword here, potentially. I would definitely like to see at least one of the following where we can say:
I have found that on several occasions I want to control things besides the look and feel of my component based on a given variant. For example, I have a TextField which is comprised of a The only way around this it seems is to create a component that wraps a There hasn't been much on this discussion in a while. Any thoughts to the options above? |
Beta Was this translation helpful? Give feedback.
-
Whilst working on the Modulz design system, I came across this interesting issue.
We have a
Separator
Component, which extendsSeparatorPrimitive
via thestyled
function.Colm created an
orientation
variant, to style it accordingly based on whether it’shorizontal
orvertical
When using this Component, I was getting the following error:
Then I realised, in Stitches, variant props are removed and not passed down to the underlying component. This is to avoid forwarding invalid DOM attributes to elements. As a side-effect, it meant that the orientation prop was never reaching the SeparatorPrimitive, which results in the error above.
To work around this error, I’ve dropped the Stitches variants in favour of the data-orientation attribute, added by the Primitives:
Not sure I’m fully satisfied with this, because:
StitchesVariants<typeof Separator>
) wont include itDemo: https://codesandbox.io/s/the-separator-war-2x8t5?file=/src/App.tsx
I'd like to open up a discussion about this:
Emotion has a
shouldForwardProp
function to customise prop forwarding. By default it forwards everything.Beta Was this translation helpful? Give feedback.
All reactions