Skip to content

Arbitrary variant nesting selector doesn't work with data attribute selector #13523

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
johtso opened this issue Apr 14, 2024 · 2 comments
Closed

Comments

@johtso
Copy link

johtso commented Apr 14, 2024

What version of Tailwind CSS are you using?

v3.4.3

What build tool (or framework if it abstracts the build tool) are you using?

N/A

What version of Node.js are you using?

N/A

What browser are you using?

Chrome

What operating system are you using?

macOS

Reproduction URL

https://play.tailwindcss.com/0ypNCIcob4

Describe your issue

Arbitrary variants allow you to only apply a class if it is the child of an element matching a selector.

This can be done like so: [.parentclass_&]:text-blue-600

You can also match based on data attributes like so: data-[parentdata='true']:text-blue-600

For some reason combining the two does not seem to work:
data-[parentdata='true'_&]:text-blue-600
or
data-[parentdata='true']_&:text-blue-600

@wongjn
Copy link
Collaborator

wongjn commented Apr 14, 2024

parentdata='true'_& is not a valid value for the data-[]: variant. It expects only either:

  • An <ident>, corresponding to data-<ident> attribute existence.
  • An <ident>=<value>, corresponding to data-<ident>="<value>".

For your case, it seems you could achieve your goal via a group-data-* variant: https://play.tailwindcss.com/7DmAySMH3P

@johtso
Copy link
Author

johtso commented Apr 14, 2024

Thanks! That looks much cleaner too..

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

No branches or pull requests

3 participants