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

Move important selector to the front when @apply-ing selector-modifying variants in custom utilities #8313

Merged
merged 2 commits into from May 9, 2022

Conversation

thecrypticace
Copy link
Contributor

Previously when given using an important selector (ex: #myselector), adding custom utilities to the utilities layer, using @apply, and a class with a selector-modifying variant was applied we would put the selector in the wrong place — before the important selector. It's important to note that this behavior is correct for non-utility/user-defined CSS but is not correct for generated utilities.

Now, when using @layer utilities or @layer components and applying a class that modifies the selector — like group-hover:underline — we now place the selector after the important selector when there is one.

tl;dr:

Before:

/* input.css */
@tailwind utilities;
@layer utilities {
  .custom-utility {
    @apply font-normal group-hover:underline;
  }
}

/* output.css */
#myselector .custom-utility {
  font-weight: 400;
}

.group:hover #myselector .custom-utility {
  text-decoration-line: underline;
}

After:

/* input.css */
@tailwind utilities;
@layer utilities {
  .custom-utility {
    @apply font-normal group-hover:underline;
  }
}

/* output.css */
#myselector .custom-utility {
  font-weight: 400;
}

/** This is the the part that has been changed */
#myselector .group:hover .custom-utility {
  text-decoration-line: underline;
}

Fixes #8305

@thecrypticace thecrypticace changed the title Fix generated utilities using @apply with important selectors Move important selector to the front when Applying selector-modifying variants in custom utilities May 9, 2022
@thecrypticace thecrypticace changed the title Move important selector to the front when Applying selector-modifying variants in custom utilities Move important selector to the front when @apply-ing selector-modifying variants in custom utilities May 9, 2022
@thecrypticace thecrypticace merged commit b49dc7c into master May 9, 2022
@thecrypticace thecrypticace deleted the fix/apply-utilities-with-important-selector branch May 9, 2022 18:20
thecrypticace added a commit that referenced this pull request May 10, 2022
…ifying variants in custom utilities (#8313)

* Fix generated utilities using `@apply` with important selectors

* Update changelog
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 this pull request may close these issues.

Using custom variants in utilities with important feature
1 participant