-
Notifications
You must be signed in to change notification settings - Fork 657
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
Tailwind classes do not work as prop of component #1250
Comments
I think this might be happening because they are being turned into styles to your component and passing them as props. I also saw something related to this when someone was asking about how they could use tailwind-merge with our Tailwnd component. This is certainly a bug that causes unexpected behavior, some case we are missing to add treatment for, but these kinds of experiments might reveal a bit of insight into what is happening here. |
this way? because i have the same behavior const ComponentX = ({ className }) => {
return (
<p className={`mb-8 text-red-500`}>
<span className={className}>Im a component</span>
</p>
)
}
export default function Email() {
return (
<Main>
<Container className="px-4">
<Text className="text-3xl">Hello world</Text>
<ComponentX className="text-blue-500 bg-black foo bar" />
</Container>
</Main>
)
} <p style="margin-bottom:32px;color:rgb(239,68,68)">
<span class="foo bar">Im a component</span>
</p> |
I mean like this const ComponentX = ({ className, style }) => {
return (
<p className={`mb-8 text-red-500 ${className}`} style={style}>
Im a component
</p>
)
}
export default function Email() {
return (
<Main>
<Container className="px-4">
<Text className="text-3xl">Hello world</Text>
<ComponentX className="text-blue-500 bg-black foo bar" />
</Container>
</Main>
)
} |
Well, it works only if the added class does not exist before, see class const ComponentX = ({ className, style }: { className?: string; style?: any }) => {
return (
<p className={`mb-8 text-red-500 ${className}`} style={style}>
Im a component
</p>
)
}
export default function Email() {
return (
<Main>
<Container className="px-4">
<Text className="text-3xl">Hello world</Text>
<ComponentX className="text-blue-500 bg-black foo bar" />
</Container>
</Main>
)
} <p class="foo bar" style="color:rgb(239,68,68);background-color:rgb(0,0,0);margin-bottom:32px">Im a component</p> the class |
Ok, so this seems like another issue, then two things break this:
I think your second issue there also would be helped a lot by being able to use tailwind merge here. |
Well yes, tailwind-merge solved my second problem, thanks for that suggestion. About the first problem, it's a bit tedious, but it's not something that keeps me awake at night, so I'll wait quietly if they can fix this bug. Thanks for the help! |
What we currently do on the Tailwind component is do a pass over the JSX tree This is probably what is generally harmful here, maybe what we should do instead is inline styles Lmk if this makes sense in your situation here, tailwind merge's behavior is also something to consider |
Waiting on #1124 to be merged before working on this. |
I have the same issue, tailwind color classes dont apply when above pattern is followed. Its becoming very difficult to build components that can be reused with this bug around. |
Weirdly, for me this somehow worked - for my
I have no idea how or why this works, would be great if you can shed some light, as its very counter intuitive and is very different from how developers usually build components |
I'm also seeing this. If i make a component like this: export const Paragraph = ({
children,
className,
style,
strong,
...props
}: ParagraphProps) => {
const classes = cn(
'text-black text-m font-normal not-italic leading-normal',
{ 'font-bold': strong },
className
)
if (props.test) {
console.log('[P] classes', classes)
}
return (
<Text className={classes} style={style} {...props}>
{children}
</Text>
)
} and then use it like this: <P strong test="true" className="font-semibold">
If you need to reschedule or cancel your call
</P> The rendered paragraph has font-weight
So it looks like the first render(?) has the correct class, but the second does not… |
yup, same behaviour - kind of goes against the purpose of building your own components, hope this gets fixed sometime soon |
@gabrielmfern Am I right in thinking that we need #1383 merged before this issue can be fixed? Do you think any extra changes will be required on top of those included in #1383 to fix the problem outlined in this issue? |
|
Hey everyone, I was able to find a way to fix this without #1383 and it works so much better than before. I have just released this on Let me know if it works on the new version. |
Describe the Bug
I am creating some small components to which other tailwind classes can be added as porps, but they are not being visible, but if I passed any other word as a class it works.
Here is a little demo:
with Tailwind classes
and this is the output of the component:
with Tailwind classes and random words
and this is the output of the component:
Which package is affected (leave empty if unsure)
@react-email/tailwind
Link to the code that reproduces this issue
i dont have
To Reproduce
Just create a simple component like example on description
Expected Behavior
I expect that tailwind classes can be passed as properties of a component.
What's your node version? (if relevant)
20.11.0
The text was updated successfully, but these errors were encountered: