Skip to content

@variants do not work on rules with multiple selectors #530

@iadcode

Description

@iadcode

Using the @Variants function with rules that have multiple selectors does not work as I expected it to.

Say I have the following CSS:

@variants hover {
  .a, .b {
    color: red
  }
}

This is what I expect to be output:

.hover\:a:hover, .hover\:b:hover {
  color: red
}

... but this is what I actually get:

.hover\:a, .b:hover {
  color: red
}

In this file:
https://github.com/tailwindcss/tailwindcss/blob/37493edfc7d7118c416470fa718d8e65e1bb35f0/src/util/generateVariantFunction.js
We have this block of code:

          modifySelectors: modifierFunction => {
            cloned.walkRules(rule => {
              rule.selector = modifierFunction({
                className: rule.selector.slice(1),
                selector: rule.selector,
              })
            })
            return cloned
          },

In my opinion, I feel like using rule.selector here is causing the unexpected behaviour.
Would it be better to map over the rule.selectors property instead (like below)?

      modifySelectors: modifierFunction => {
        cloned.walkRules(rule => {
          rule.selectors = rule.selectors.map(selector =>
            modifierFunction({
              className: selector.slice(1),
              selector: selector
            })
          );
        });
        return cloned;
      }

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