react-email: Tailwind classes do not work as prop of component
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
import React from 'react'
import { Text, Container } from '@react-email/components'
import { Main } from '../src/layout/CleanLayout'
const ComponentX = ({className}) => {
return <p className={`mb-8 text-red-500 ${className}`}>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" />
</Container>
</Main>
)
}
and this is the output of the component:
<p class="undefined" style="margin-bottom:32px;color:rgb(239,68,68)">Im a component</p>
with Tailwind classes and random words
import React from 'react'
import { Text, Container } from '@react-email/components'
import { Main } from '../src/layout/CleanLayout'
const ComponentX = ({className}) => {
return <p className={`mb-8 text-red-500 ${className}`}>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>
)
}
and this is the output of the component:
<p class="foo bar" style="margin-bottom:32px;color:rgb(239,68,68)">Im a component</p>
Which package is affected (leave empty if unsure)
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
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 16 (7 by maintainers)
@WillsB3 I actually have a fix for this on a branch, but there’s no PR for it yet. It requires #1383 to be merged for it to work properly.
Weirdly, for me this somehow worked - for my
Textwrapper componentI 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
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
@react-email/tailwind@0.1.0-canary.1or@react-email/components@0.0.23-canary.2.Let me know if it works on the new version.
Ok, so this seems like another issue, then two things break this:
styleprop that have classNames do not work properlyI think your second issue there also would be helped a lot by being able to use tailwind merge here.
I mean like this