Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Custom "important" variant not working #92

Closed
jameslkingsley opened this issue Mar 17, 2021 · 6 comments · Fixed by #174
Closed

Custom "important" variant not working #92

jameslkingsley opened this issue Mar 17, 2021 · 6 comments · Fixed by #174

Comments

@jameslkingsley
Copy link

This particular variant isn't working right now (0.1.2):

addVariant('important', ({ container }) => {
    container.walkRules(rule => {
        rule.selector = `.\\!${rule.selector.slice(1)}`

        rule.walkDecls(decl => {
            decl.important = true
        })
    })
})

The expected classes (eg. !bg-red) aren't generated/kept when evaluating this kind of markup (<p class="!text-red">)

@adamwathan
Copy link
Member

Yeah this is a limitation of how variants have to work in the new engine, they are limited to the {variant}:{utility} format for the foreseeable future. We're going to add first class support for the !text-red style syntax instead 👍🏻

@jameslkingsley
Copy link
Author

jameslkingsley commented Mar 17, 2021

Ah okay gotcha - does that mean this would work instead?

addVariant('important', ({ container }) => {
    container.walkRules(rule => {
        rule.selector = `.${e('important:')}${rule.selector.slice(1)}`

        rule.walkDecls(decl => {
            decl.important = true
        })
    })
})

EDIT: Just checked, it does work

@timfee
Copy link

timfee commented Mar 20, 2021

Might want to update https://tailwindcss.com/docs/plugins#complex-variants :)

@adamwathan
Copy link
Member

Might want to update https://tailwindcss.com/docs/plugins#complex-variants :)

Why? That works in the regular Tailwind library, it's just the JIT project that has the limitation right now. Still in pre-release, lots left to do :)

@timfee
Copy link

timfee commented Mar 20, 2021 via email

@adamwathan
Copy link
Member

Added first class support for !bg-black syntax in core as of v0.1.15 👍

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

Successfully merging a pull request may close this issue.

3 participants