Skip to content

bug: join focus/hover z-index rules dropped in Tailwind v4 builds (relative selectors inside @scope) #4851

Closed

Description

@benpsnyder

Summary

In Tailwind CSS v4 builds, join loses its focus and hover z-index stacking. The two rules in packages/daisyui/src/utilities/join.css use bare relative selectors inside @scope (&):

@scope (&) {
  > :where(:focus, :has(:focus)) { @apply z-2; }
  @media (hover: hover) {
    > :where(.btn:hover, :has(.btn:hover)) { @apply z-1; }
  }
  :where(:scope > :first-child) { … }   /* other rules already use :scope > */
}

Tailwind hoists that to a top-level @scope (:is(.join)) { > :where(…) {…} }. Lightning CSS, which Tailwind uses to optimize output, rejects a relative selector directly inside @scope (Invalid empty selector) and drops both rules. So a focused or hovered join item no longer stacks above its neighbours, and its focus ring or hover border is hidden under the adjacent item's overlapping border.

Repro (daisyui 5.7.50, tailwindcss + @tailwindcss/node 4.3.4, lightningcss 1.33.0, all latest)

import { compile, optimize } from '@tailwindcss/node';

const input = `@import "tailwindcss" source(none);
@plugin "daisyui" { include: join; themes: light --default; }`;
const c = await compile(input, { base: process.cwd(), onDependency() {} });
const raw = c.build(['join', 'join-item', 'btn']);
optimize(raw, { minify: false });

Output:

Found 2 warnings while optimizing generated CSS:
│   @scope (:is(.join)) {
│      > :where(:focus, :has(:focus)) {
┆      ^-- Invalid empty selector
│       > :where(.btn:hover, :has(.btn:hover)) {
┆        ^-- Invalid empty selector

The optimized CSS has no z-index: 2 or z-index: 1 rule for .join children. Calling lightningcss.transform() directly on the compiled CSS throws SyntaxError: Invalid empty selector.

Suggested fix

Use the explicit :scope > form, like the rest of the block. It's equivalent CSS and parses everywhere:

 @scope (&) {
-  > :where(:focus, :has(:focus)) {
+  :scope > :where(:focus, :has(:focus)) {
     @apply z-2;
   }
   @media (hover: hover) {
-    > :where(.btn:hover, :has(.btn:hover)) {
+    :scope > :where(.btn:hover, :has(.btn:hover)) {
       @apply z-1;
     }
   }

We're currently carrying exactly this change as a pnpm patch on daisyui/utilities/join/object.js, and it restores the stacking.

The root parser behaviour is arguably a Lightning CSS bug, since relative selectors in @scope are valid per spec, but changing the daisyUI source fixes this for current toolchains.

Activity

  1. github-actions commented on Nov 4, 2026

    @github-actions

    Thank you @benpsnyder for reporting issues. It helps daisyUI a lot 💚
    I'll be working on issues one by one. I will help with this one as soon as a I find a solution.
    In the meantime providing more details and reproduction links would be helpful.

  2. C-Jeril commented on Nov 8, 2026

    @C-Jeril

    I ran into the same issue; for now, I’ve downgraded TailwindCSS to version 4.3.3.

  3. added a commit that references this issue on Nov 12, 2026
    c41c55b
  4. added a commit that references this issue on Nov 12, 2026
    d1c2282
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions