Skip to content

Parent state modifier without explicit parent (in-*) #13912

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

Closed
wants to merge 4 commits into from

Conversation

eloyesp
Copy link
Contributor

@eloyesp eloyesp commented Jun 28, 2024

I'm doing a follow up on #13751 where I propose a new modifier, that is a simplified "group-*" without an explicit parent.

There are many times when the styling is based on the parent state, but it is not important which parent, there are many examples of that on the tests with the form of: [.checked &]:underline, but there are many other cases, for example:

  • in-aria-busy: If any parent is busy is enough, we don't care which parent it is.
  • in-data-active: This is part of an active element.

The syntax is quite simple, the implementation is clean and the generated css is shorter than using group-* or [.checked_&]:underline, and it also allows using variants like data- and aria-.

Hope you like the idea.

eloyesp added 4 commits June 28, 2024 10:58
Add support for "in" that works like the group variant, but use any
parent (so it does not require an explicit group element).
RobinMalfait added a commit that referenced this pull request Nov 18, 2024
This PR adds a new `in-*` variant that allows you to apply utilities
when you are in a certain selector.

While doing research for codemods, we notice that some people use
`group-[]:flex` (yep, the arbitrary value is empty…). The idea behind is
that people want to know if you are in a `.group` or not.

Similarly, some people use `group-[]/name:flex` to know when you are in
a `.group/name` class or not.

This new `in-*` variant allows you to do that without any hacks.

If you want to check whether you are inside of a `p` tag, then you can
write `in-[p]:flex`. If you want to check that you are inside of a
`.group`, you can write `in-[.group]`.

This variant is also a compound variant, which means that you can write
`in-data-visible:flex` which generates the following CSS:
```css
:where([data-visible]) .in-data-visible\:flex {
  display: flex;
}
```

This variant also compounds with `not-*`, for example:
`not-in-[.group]:flex`.

Additionally, this PR also includes a codemod to convert `group-[]:flex`
to `in-[.group]:flex`.

---

This was proposed before for v3 in #13912

---------

Co-authored-by: Eloy Espinaco <eloyesp@gmail.com>
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
@thecrypticace thecrypticace requested a review from a team as a code owner December 3, 2024 19:05
@RobinMalfait RobinMalfait changed the base branch from main to v3 January 27, 2025 11:19
@RobinMalfait RobinMalfait self-assigned this Jan 28, 2025
@RobinMalfait
Copy link
Member

Hey!

Now that Tailwind CSS v4 is out, we won't be adding more features to v3. That said, we did implement this feature in v4 so I would highly recommend to upgrade to v4 if you can!

We wrote an upgrade guide and included some tooling to upgrade your projects to minimize the amount of work you have to do yourself. More info: https://tailwindcss.com/docs/upgrade-guide

Docs related to the in-* variant: https://tailwindcss.com/docs/hover-focus-and-other-states#implicit-groups

Thanks again for this feature!

@eloyesp
Copy link
Contributor Author

eloyesp commented Jan 29, 2025

Yes, I already saw it and I'm already using this! Thanks a lot!

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