Skip to content

Question about new addVariant API #6757

Discussion options

You must be logged in to vote

Hey! Thank you for your question!
Much appreciated! 🙏

Maybe we can optimize this internally, but in most cases using &[foo="bar"] is currently the best way of defining new variants. However, it also depends a bit on your use case. This is because & will be replaced by the parent selector. So for example if we define 2 variants like foo and bar:

addVariant('foo', '&[foo="bar"]')
addVariant('bar', '[foo="bar"]&')

And have the following html:

<div class="group p-12">
  <div foo="bar" class="foo:group-hover:text-green-500">Hello world</div>
  <div foo="bar" class="bar:group-hover:text-green-500">Hello world</div>
</div>

Then we would generate the following CSS:

.group:hover .foo\:group-hover\…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@MichaelAllenWarner
Comment options

Answer selected by MichaelAllenWarner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants