Talking with a client about Tailwind.

kerryboyko

Kerry Boyko

Posted on September 15, 2023

Talking with a client about Tailwind.

I've been working on a 6wk contract gig to shore up some code, and the previous developer decided to go with Tailwind. I've mentioned why I think that's a bad idea before, but I had to explain to my new clients some of the problems that have happened because of that initial poor choice:


ME: So - I realise that it was another {my contractor} developer who chose to add Tailwind to this project. I don't know his or her reasoning. I can tell you, however, that one of the big problems with using Tailwind to create UI components is that it is extremely difficult (near impossible) to overwrite those properties assigned by tailwind utility classes when trying to extend a component to have the same functionality but different styles.

I think for now it's best to just create a seperate "TransparentButton" and "RippleButton" components which are independent of the Button component defined in {our UI library}.

Response:

I believe the overall goal with adding tailwind was to reduce the number of components and or css classes/styling we have to maintain. Ideally we maintain "nothing" outside of our core value prop and can just plug & play industry standard components & libraries.

I think that is a noble goal. Unfortunately, in practice, I find Tailwind to actually be counterproductive to that goal, because since you can't just make minor tweaks to existing libraries, or existing components, you end up having to recreate entire components from scratch.

This is mostly because CSS does something Tailwind doesn't - it cascades.

That is, if the library has a button called "Button" with the className of "bg-orange", it will have an orange background. I can't then modify Button with react props or adding more Tailwind classes to create a button that is identical except it has different styling, (such as a transparent background).

On the other hand, if the library's Button component were created with a CSS file associated with the class .button, where button was defined as

.button { 
  background-color: orange; 
}
Enter fullscreen mode Exit fullscreen mode

I could simply use that component, add another class name (.transparent-button, for example) and then define the .transparent-button with

.transparent-button { 
  background-color: transparent;
}
Enter fullscreen mode Exit fullscreen mode

The computer will read <button class="button transparent-button">Button</button> as "First apply the .button styles. Then apply the .transparent-button styles, overwriting any styles that are different."

Tailwind doesn't have that functionality, in part because a design choice of tailwind is that it sorts class definitions according to it's own criteria (which I presume is alphabetical) in the tailwind postprocessor, not based on the order in which you write them.

So, If you were to define <button class="bg-orange bg-transparent"/> then Tailwind would apply the orange. Because (I presume) "bg-o" comes before "bg-t" alphabetically.

💖 💪 🙅 🚩
kerryboyko
Kerry Boyko

Posted on September 15, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related