Skip to content
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

Group Class with prefix config doesn't work #11384

Closed
vityapro opened this issue Jun 6, 2023 · 9 comments · Fixed by #11454
Closed

Group Class with prefix config doesn't work #11384

vityapro opened this issue Jun 6, 2023 · 9 comments · Fixed by #11454
Assignees

Comments

@vityapro
Copy link

vityapro commented Jun 6, 2023

What version of Tailwind CSS are you using?

For example: v3.3.2

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

For example: postcss-cli 8.3.1

What version of Node.js are you using?

For example: v14.5.0

What operating system are you using?

For example: Ubuntu

Reproduction URL
https://play.tailwindcss.com/cxSWYn1qBg

Describe your issue

Have issue with prefix config and group hover
prefix: 'tw-'

parent : group
children: group-[.class]:tw-hidden

@thecrypticace thecrypticace self-assigned this Jun 7, 2023
@calvinagar
Copy link

calvinagar commented Jun 18, 2023

I'm having this issue as well, except in my case I'm using custom variants as described here.

hocus works just fine, but group-hocus does not work as described in the docs.

Tailwind Play

@thecrypticace
Copy link
Contributor

@calvinagar The 2nd argument to addVariant is a selector or list of selectors.

What you want is to write this as:

addVariant('group-hocus', [':merge(.group):hover &', ':merge(.group):focus &'])

Here's a Tailwind Play of that working.

@calvinagar
Copy link

Works perfectly, thank you!

@ghost
Copy link

ghost commented Jun 20, 2023

It doesn't work with named groups tho...

Example:
group-hocus/body:bg-black

@thecrypticace
Copy link
Contributor

Hey! We've merged the fix for this in #11454. It'll be available in our next tagged release. In the meantime you can test it via our insiders build (it may take a few minutes to build & publish):

npm install tailwindcss@insiders

Thanks for reporting it! ✨

@Movsar-Khalakhoev
Copy link

@thecrypticace Hi! As @stijn-code mentioned, nested groups don't work with custom variants. Is this a bug or is it impossible to create nested groups with custom variants? I wrote a demo project Playground
Thank you for tailwind!

@thecrypticace
Copy link
Contributor

thecrypticace commented Jul 6, 2023

@Movsar-Khalakhoev Named groups use the matchVariant API — this is also available for you to use! Any variant can be defined with this API to gain support for modifiers (the thing that named groups and named peers use internally). There's nothing "special" in Tailwind CSS about using the group name or class in a variant that enables name/modifier support.

For your case the group variant includes support for custom selectors already — as an arbitrary value:

<div class="group-[&[data-loading=true]]/foo:bg-red-500"></div>

However, if you want a more terse syntax (like group-loading/foo) you can use the matchVariant API to add a custom variant that also supports names:

matchVariant(
  'group-loading',
  (_, { modifier }) => {
    return modifier
      ? `:merge(.group\\/${modifier})[data-loading=true] &`
      : `:merge(.group)[data-loading=true] &`
  },
  {
    // The `DEFAULT` value here lets you use group-loading/foo without an arbitrary value
    // Otherwise you'd always have to write it as group-loading-[something-here]/foo:bg-red-500
    values: { DEFAULT: null },
  }
)

Here's a Tailwind Play of this working.

@Movsar-Khalakhoev
Copy link

@thecrypticace Thank you for your help! This is exactly what I need!

@ghost
Copy link

ghost commented Jul 6, 2023

Hi @thecrypticace,

Thanks for the example, but isn't this something that can automatically be fixed in your code? Or will this be the way till we have Tailwind 4? 😝

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 a pull request may close this issue.

4 participants