Replies: 5 comments 12 replies
-
Thank you! It's really useful in many case, hope it become officially built-in api. |
Beta Was this translation helpful? Give feedback.
-
Thanks, @wolthers |
Beta Was this translation helpful? Give feedback.
-
I hope they do add this, seriously. Also, to get this to work with Nuxt 3, I had to write it without the // tailwind.config.js
module.exports = {
....
plugins: [
function groupPeer({ addVariant }) {
let pseudoVariants = [
// ... Any other pseudo variants you want to support.
// See https://github.com/tailwindlabs/tailwindcss/blob/6729524185b48c9e25af62fc2372911d66e7d1f0/src/corePlugins.js#L78
"checked",
].map((variant) =>
Array.isArray(variant) ? variant : [variant, `&:${variant}`],
);
for (let [variantName, state] of pseudoVariants) {
addVariant(`group-peer-${variantName}`, (ctx) => {
let result = typeof state === "function" ? state(ctx) : state;
return result.replace(/&(\S+)/, ":merge(.peer)$1 ~ .group &");
});
}
},
],
...
}; |
Beta Was this translation helpful? Give feedback.
-
👍🏻 we need sth to implmenent this standard pattern
|
Beta Was this translation helpful? Give feedback.
-
If I'm not mistaken, you can achieve this by using example: <input type="checkbox" class="peer" />
<div class="text-blue-400 peer-checked:text-red-500 group">hello
<div></div>
<div class="peer-checked:group-[]:hidden">Icon</div>
</div> https://play.tailwindcss.com/NT2vsY9Al5 Update: <input type="checkbox" class="peer" />
<div class="text-blue-400 peer-checked:text-red-500 group">hello
<div></div>
<div class="group-peer-checked:hidden">Icon</div>
</div> |
Beta Was this translation helpful? Give feedback.
-
Usecase:
When writing a custom checkbox or radio component it is often desirable to be able to style children of a group depending on the state of a sibling of the group.
Proposed implementation:
Currently solvable with a plugin like this, but usecase is common enough that I think it makes sense to integrate.
If I understand the source well enough, it should be relatively straight forward to add in the pseudoClass variants block here:
tailwindcss/src/corePlugins.js
Line 77 in 6729524
Beta Was this translation helpful? Give feedback.
All reactions