Skip to content

Allow @custom-variant to redefine built-in variants with proper order. #18070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

Aurailus
Copy link

Summary

Adds an "override" property to the object bag passed to Variants.static which forces a variant to get a new order even if it has already been defined. This property is set in index.ts:399 for the @custom-variant rule to allow custom variants to redefine existing variants like active: and have them be properly ordered relative to other custom variants, a.l.a tailwind v3. See #18067 for the motivating regression.

Test plan

Tested using the playground directory. This is a very insignificant (~17 LOC) change which I don't expect to cause many new issues. I can add more robust testing if necessary, just let me know.

@Aurailus Aurailus requested a review from a team as a code owner May 17, 2025 03:17
@Aurailus Aurailus changed the title Add "override" option to Variants.static which allows overrides of … Allow @custom-variant to redefine built-in variants with proper order. May 17, 2025
@thecrypticace
Copy link
Contributor

The fact that a redefined variant reuses its order was an intentional design decision. This lets someone override hover in place without necessarily affecting how it works relative to the order of other variants. e.g. to tweak or remove the media query for it entirely. If we did not do that then tweaking the selector for a variant could result in things no longer matching the way they did relative to other variants.

For example, if this moved hover to the end:

@custom-variant hover (&:hover);

Then this div would still be blue when clicked when all someone was doing was trying to remove the media query from hover that we ship with by default:

<div class="bg-red-500 hover:bg-blue-500 active:bg-green-500 size-32"></div>

Changing this now could break backwards compatibility with previous 4.x releases in subtle and unexpected ways so I don't see us doing this.

@Aurailus
Copy link
Author

Aurailus commented May 19, 2025

@thecrypticace so then how do you propose resolving this in practice? Because this is a regression from the behaviour of Tailwind 3.x. Perhaps a @undef-variant hover; rule or something to undefine a variant so it can get a new order?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants