Use :is
to make important selector option insensitive to DOM order
#10835
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR changes the implementation of the important option's selector strategy to wrap the underlying selector with
:is(...)
to make it insensitive to DOM order. This is especially useful when using the "class" dark mode strategy, or using thertl
andltr
modifiers because it allows you to add the.dark
class ordir="rtl"
attributes to the<html>
element instead of to some descendant of the element where you've added your important selector.For example, given this configuration:
...Tailwind would historically generate classes like this:
That means that this DOM structure wouldn't work:
With the changes in this PR, Tailwind will generate this CSS instead:
...which means the above DOM structure will work, which is more intuitive behavior.
The
:is(...)
pseudo-class has good browser support, with the most recent adopter being Safari in v14, which is almost three years old and two major versions in the past.