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

Forward modifier from has-* and not-* variants to compounded variant #14935

Open
wants to merge 3 commits into
base: next
Choose a base branch
from

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Nov 9, 2024

This PR fixes an issue where using a modifier in combination with has-* or not-* doesn't work as expected.

If you have the following HTML:

<div class="group/parent" data-visible="">
  <div class="group-data-visible/parent:text-red-500"></div>
</div>

Then the following CSS is generated:

.group-data-visible\/parent\:text-red-500:is(:where(.group\/parent)[data-visible] *) {
  color: var(--color-red-500);
}

But if you want to use it with not-*, then nothing is being generated:

<div class="group/parent" data-visible="">
  <div class="not-group-data-visible/parent:text-red-500"></div>
</div>
/* <EMPTY> */

But with this PR, we will forward the modifier parent from the not variant, to the group variant, so the following CSS is generated:

.not-group-data-visible\\/parent\\:text-red-500:not(:where(.group\\/parent)[data-visible] *) {
  color: var(--color-red-500);
}

This is also implemented for has-*

@RobinMalfait RobinMalfait marked this pull request as ready for review November 10, 2024 12:06
@RobinMalfait RobinMalfait requested a review from a team as a code owner November 10, 2024 12:06
@RobinMalfait RobinMalfait enabled auto-merge (squash) November 15, 2024 18:59
} else {
return null
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels super weird to me to mutate the variant we're getting. Could this be handled in parseCandidate or something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though I guess we'd need some additional metadata for that to work right. I guess as long as this isn't guaranteed to "break" non-compounded versions of the same variant (do we have a test for that?) then it's probably fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the mutation breaks stuff:

Screenshot 2024-11-15 at 14 08 38

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handling it during parsing might break things as well, especially when we re-print a candidate.

Copy link
Contributor

@thecrypticace thecrypticace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hopefully can fix this w/o too much hassle

Comment on lines +560 to +566
// Forward modifier from `not-*` and `has-*` variants to the
// compound variant.
if (modifier !== null && (root === 'not' || root === 'has')) {
value = `${value}/${modifier}`
modifier = null
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more correct, but feels so wrong in this spot

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah agree it does feel wrong 🤔

Could in theory add a forwardsModifier() method to Variants and control it from there? Gonna think on this some

@RobinMalfait RobinMalfait force-pushed the feat/forward-modifier branch 2 times, most recently from 1183f3b to 0349a86 Compare November 18, 2024 12:54
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.

2 participants