Add a new twClear
(or something like that) function
#76
Replies: 3 comments 7 replies
-
By the way, you may remember I was the one that created #70 as well, and this would pretty much resolve that discussion too because it reduces the "boilerplate" required to use this library to just what is necessary to make it work. |
Beta Was this translation helpful? Give feedback.
-
Yeah you're right, that behavior of Vue doesn't work well with tailwind-merge. I'm not sure whether creating a But I'm thinking about the option of adding something to the config so you can hook into the merging behavior of tailwind-merge. Maybe something like const twMerge = extendTailwindMerge({
mergeClasses(/* some args here */) {
// Custom merging behavior defined here
}
}) What do you think? |
Beta Was this translation helpful? Give feedback.
-
@AaronBeaudoin @dcastil <a class="text-sm" :class="{ 'color-red-100' : active, 'color-green-100' : !active }" >Link</a> How do I use twMerge? |
Beta Was this translation helpful? Give feedback.
-
In Vue, I've found the most convenient way to use
twMerge
is something like this:Attach the function to my Vue app as a global property so it can be accessed in any component like
$twMerge
.Use it like this:
There's only one problem. Vue appends classes from where components are used to the classes inside the component. So if I use the component like this:
The actual HTML ends up being this:
This is because the
twMerge
function does it's job correctly, but then Vue ends up tacking on the classes afterwards causing them to be added to the element twice. The reality is that this won't actually cause any real problems since duplicate classes won't affect the style in any negative way. However, it's ugly and does have an effect on the final size of the HTML.So I propose that some sort of
twClear
function be added. This function would do the merging just liketwMerge
, but instead of keeping the last conflicting class it would just remove conflicting classes. Like this:That way, in the situation above I could just do this:
And then when I use the component like this:
I would just get this:
Beta Was this translation helpful? Give feedback.
All reactions