disabled prefix does not work
See original GitHub issueDescribe the problem:
Classes do not work with disabled:
prefix.
tailwind version 1.9.5
Link to a minimal reproduction:
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
Why isn't the "disabled:" tailwind prefix working in my react app?
No matter what value I pass to the disable attribute, disabled="" get's rendered in the HTML. I even tried to use an input...
Read more >Re: --without-local-prefix Does Not Work
Re: --without-local-prefix Does Not Work ... Specifying "no" does not disable the use of local_prefix, nor should > it.
Read more >How to enable/disable a prefix/suffix on Android devices?
For a prefix/suffix to be enabled/disabled the following steps are recommended: Settings; Scanning; Internal Scanner; Default Profile ...
Read more >Disable Prefix in WH Partition Table - MicroStrategy
Disable Prefix in WH Partition Table. The Disable Prefix in WH Partition Table is an advanced property that is hidden by default. For...
Read more >Configure IPv6 for advanced users - Windows Server
If you do, some Windows components may not function. We recommend using Prefer IPv4 over IPv6 in prefix policies instead of disabling IPV6....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s still not working for me, here is my tailwind.config.js:
For anyone confused by this problem, here’s REPL with the entire solution: https://play.tailwindcss.com/Hxe9LondgZ?file=config
First, notice in the config, we’ve specified all the variants that are applicable to backgroundColor:
backgroundColor: ['responsive', 'hover', 'focus', 'active', 'disabled']
The documentation says this is necessary because even if you extend a variant array always replaces any other existing variants. So, if you don’t list out every variant and only put “disabled” you will only be enabling “disabled” and essentially turning everything else off that is optional (hover, focus, and active in this case, as those are the ones we want.) Next, notice that “disabled” is the last item in the list, giving it the highest precedence. We want disabled to overrule everything else.
Next, notice that the classes for hover, active, and disabled are all modifying the same CSS Attribute: backgroundColor (in Tailwind, “bg-”):
<button class="p-8 bg-green-800 hover:bg-yellow-400 active:bg-blue-800 disabled:bg-red-800" disabled>Should be red</button>
This is important, because while disabled overrules hover if you specify the following:
text-white hover:text-gray disabled:bg-red-800
You will get incorrect behavior: The text will be white when the button is just sitting there, the text will be white when disabled, but the text will turn gray when you hover! But the button is disabled right? So it shouldn’t response to hover! But hover is still being applied by CSS even though the button is disabled. That’s just how CSS works.
So, in Tailwind, you’d have to use:
text-white hover:text-gray disabled:text-white disabled:bg-red-800
Text is white when it’s just sitting there. Gray when hovered and enabled. When it’s disabled and hovered, its white because disabled overrules hover and white wins over Gray.
TLDR: 1) Specify all the variants in your config, not just the ones you are adding. 2) Your disabled: styling must “undo” all the attributes that hover:, focus:, and active: set to make the button seem like it’s fully disabled.