I have some buttons styled with TailwindCSS.
These buttons contains some icons / helper text (<span>
) that should receive a color (different than the color used for button text) when the mouse is over the button.
I used the group
class on button, and then in the inner element:
<script src="https://cdn.tailwindcss.com#.js"></script>
<button class="group bg-indigo-500 hover:enabled:bg-indigo-400 disabled:cursor-not-allowed">
<span class="group-hover:text-pink-900">helper text</span>
</button>
<button disabled class="group bg-indigo-500 hover:enabled:bg-indigo-400 disabled:cursor-not-allowed">
<span class="group-hover:text-pink-900">helper text</span>
</button>
Notifce that the hover effect is set only when the button is enabled (by using hover:enabled
).
If the button is disabled, I want to disable this hover effect on the helper text well.
I’ve tried group-hover:enabled:text-pink-900
, but it does not work.
disabled:pointer-events-none
is not an option for me, because it will break disabled:cursor-not-allowed
.
5
Answers
I've managed to get the desired behaviour by combining
group-*
modifiers like this:group-hover:group-enabled:...
Explanation:
group-hover:group-enabled:text-indigo-900
=> produces the following css rule:Example: https://play.tailwindcss.com/6BmIcNS610
You gotta check if it is disabled or not this should be fix ur issue
you can do this, "disabled:pointer-events-none"
Can you please check the below solution? Hope it will work for you.
Example:
https://play.tailwindcss.com/hXHNBTxnvz
I had a similar issue recently, to solve it hide the helper text initially using
invisible
andpointer-events-none
classes. Then make it visible and enable hover effects only when the button is hovered (group-hover:visible
). This way, the hover effect is disabled when the button is disabled, this should achieve the desired behaviour: