tailwindlabs / tailwindcss

A utility-first CSS framework for rapid UI development.
https://tailwindcss.com/
MIT License
83.27k stars 4.22k forks source link

Add new `in-*` variant #15025

Closed RobinMalfait closed 3 days ago

RobinMalfait commented 4 days ago

This PR adds a new in-* variant that allows you to apply utilities when you are in a certain selector.

While doing research for codemods, we notice that some people use group-[]:flex (yep, the arbitrary value is empty…). The idea behind is that people want to know if you are in a .group or not.

Similarly, some people use group-[]/name:flex to know when you are in a .group/name class or not.

This new in-* variant allows you to do that without any hacks.

If you want to check whether you are inside of a p tag, then you can write in-[p]:flex. If you want to check that you are inside of a .group, you can write in-[.group].

This variant is also a compound variant, which means that you can write in-data-visible:flex which generates the following CSS:

:where([data-visible]) .in-data-visible\:flex {
  display: flex;
}

This variant also compounds with not-*, for example: not-in-[.group]:flex.

Additionally, this PR also includes a codemod to convert group-[]:flex to in-[.group]:flex.


This was proposed before for v3 in #13912