-
I'm adding twind to an existing React project with its own CSS (via emotion). I noticed that twind styles are well isolated to the components that use them, but once the component unmounts, some of the base styles (resets, I think) linger on the page. Is there a recommended approach to cleanly removing these when the component is unmounted? |
Beta Was this translation helpful? Give feedback.
Replies: 20 comments 5 replies
-
To clarify, I think I want to keep the preflight in place. I tried |
Beta Was this translation helpful? Give feedback.
-
Why do you want them to be removed? They are in a style element. Your emotion styles are kept as well. |
Beta Was this translation helpful? Give feedback.
-
There's is some overlap between the twind base styles/resets and the existing styles on the page that I am trying to resolve. We're introducing twind incrementally, and the overlap in styles makes it hard to do so. Maybe what I'm looking for is a virtual sheet that is mounted alongside each component that uses twind? |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I see! Got you. The preflight causes issues. You want a scoped preflight. That may be difficult because the additional scope like To solve that you must then increase the specificity of all Twind generated classes for example using the Sadly Twind does not have a configurable way to increase the specificity for all generated classes. |
Beta Was this translation helpful? Give feedback.
-
Oh perfect, this might be exactly what I need. Will report back. Thank you for the quick help! |
Beta Was this translation helpful? Give feedback.
-
Oof, yeah, the specificity does not play nicely with other things. For example, all of react-select's default styles get reset when in a Any other ideas? |
Beta Was this translation helpful? Give feedback.
-
No preflight – but a base style that is applied to all elements that are styled with Twind: Example Or with hashed classes there is no need for a custom |
Beta Was this translation helpful? Give feedback.
-
@holic Did the last comment help? |
Beta Was this translation helpful? Give feedback.
-
Thanks for checking back in. I think it helped somewhat. There’s this disappearing bottom border thing I discovered when there’s no preflight that I’m trying to debug, but needed to move on to something else yesterday. Will be poking at this some more on Monday.
… On Mar 5, 2021, at 6:51 AM, Sascha Tandel ***@***.***> wrote:
@holic Did the last comment help?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Beta Was this translation helpful? Give feedback.
-
Here's the issue I was seeing. With preflight disabled, some of the borders don't appear. If you remove As far as I can tell from the Chrome inspector, these borders should appear - they aren't grayed out/struckthrough like I would expect if they were being overridden by other styles. |
Beta Was this translation helpful? Give feedback.
-
Ah, maybe it's the lack of this in the base style? If I add It's not until I add both |
Beta Was this translation helpful? Give feedback.
-
Have you checked this comment: #134 (comment) It is working there. Example |
Beta Was this translation helpful? Give feedback.
-
BTW: I changed the title because we may be on to something here. That could evolve into an own module like twind/scoped import { tw, setup } from 'twind/scoped' |
Beta Was this translation helpful? Give feedback.
-
I did but Typescript was complaining about those spreads. Even if I add Here's a better reproduction of how I'm using twind and where it's not working. Maybe it's because the Edit: Nope, that's bad too, because then all downstream components get unset (e.g. a Bootstrap input field loses its border). Maybe we need all descendant selectors/classes to be prefixed with I might just live with the simple |
Beta Was this translation helpful? Give feedback.
-
You need to cast them: import type { CSSRules } from 'twind'
setup({
// Define base style for all Twind rules
preflight: ({ html, body, '*,::before,::after': borderBox, }) => ({
'.tw': {
// Order is important
...(body as CSSRules),
...(html as CSSRules),
...(borderBox as CSSRules),
margin: '0',
padding: '0',
'&::before,&::after': borderBox
}
}),
})
Then we ran into specificity issues again. Maybe we should get the I will stop looking for solutions. But if you need any help or have questions please reach out to me. I would like to move this issue into discussions because I do not really see this as an issue with twind or something that could be solved by twind. Would that be OK with you? |
Beta Was this translation helpful? Give feedback.
-
That seems reasonable! Thanks for all the help 🙏 |
Beta Was this translation helpful? Give feedback.
-
Just a reminder for later: we could use the :where selector which always has 0 specificity. |
Beta Was this translation helpful? Give feedback.
-
@holic @sastan Works great for my use case, hope others might find value!
|
Beta Was this translation helpful? Give feedback.
-
Hello! We would love to have a TwindWrapper that enables twind only for its children and grand children. The examples in esm.codes have disppeared and a long time has passed so I was wondering if there is a better /simple way to create this wrapper that isolates the twind runtime classes. Thanks! |
Beta Was this translation helpful? Give feedback.
That seems reasonable! Thanks for all the help 🙏