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

The not- variant does not work as expected with named groups (group/{name}) #15772

Open
rentalhost opened this issue Jan 23, 2025 · 3 comments
Open

Comments

@rentalhost
Copy link

What version of Tailwind CSS are you using?

v4.0.0

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

Tailwind Play (https://play.tailwindcss.com/)

What version of Node.js are you using?

What browser are you using?

Chrome 131

What operating system are you using?

Windows 11

Reproduction URL

https://play.tailwindcss.com/DKPgTfOLF0

Describe your issue

<!-- Named group (does NOT work) -->  
<div class="group/test bg-red-50 p-8">  
  <div class="not-group/test-hover:text-red-500">Text (should be red when group is NOT hovered)</div>  
</div>  

<!-- Unnamed group (works correctly) -->  
<div class="group bg-green-50 p-8">  
  <div class="not-group-hover:text-green-500">Text (green when group is NOT hovered)</div>  
</div>  

Current Behavior:

  • The not-group/test-hover:text-red-500 class does not apply styles when the named group (group/test) is not hovered.
  • The not-group-hover:text-green-500 class works as intended for the unnamed group.

Expected Behavior:

Both named and unnamed groups should support the not- variant (e.g., not-group/{name}-hover and not-group-hover) to apply styles when the parent group is not in the specified state.

@ozipoetra
Copy link

I also have this problem on tailwind 4 and also on mobile browsers the hover group doesn't work but on desktop it's working properly

@wongjn
Copy link
Contributor

wongjn commented Jan 29, 2025

From the beta docs:

In v4.0 we’ve updated the hover variant to only apply when the primary input device supports hover:

@media (hover: hover) {
  .hover\:underline:hover {
    text-decoration: underline;
  }
}

This can create problems if you’ve built your site in a way that depends on touch devices triggering hover on tap. If this is an issue for you, you can override the hover variant with your own variant that uses the old implementation:

@import "tailwindcss";

@variant hover (&:hover);

Generally though I’d recommend treating hover functionality as an enhancement, and not depending on it for your site to work since touch devices don’t truly have the ability to hover.

@KennethHoff
Copy link

KennethHoff commented Jan 30, 2025

This is unrelated to hover. not-* and group/<name> doesn't interact currently.

The following code doesn't work either:

<div className="group/test">
	<input type="checkbox" />

    <!-- This changes its state based on the condition of the checkbox -->
	<div className="group-has-checked/test:hidden">Checked</div>

    <!-- This always renders regardless of checkbox state -->
	<div className="not-group-has-checked/test:hidden">Not checked</div>
</div>

For completeness sake, this does work:

<div className="group">
	<input type="checkbox" />
	<div className="group-has-checked:hidden">Checked</div>
	<div className="not-group-has-checked:hidden">Not checked</div>
</div>

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

4 participants