Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TailwindCSS: disabled variant not working

Tags:

tailwind-css

I am trying to use disabled variant in tailiwnd, but it does not seem to work. I do not know what to do.

I want to change button apperance if it is disabled, I have read the documentation and it says 'disabled' variant in not enabled by default. So I modify my tailwind.config.js and now it looks like this:

module.exports = {
  purge: [],
  theme: {
    extend: {},
  },
  variants: {
    extend: {
      opacity: ['disabled']
    }
  },
  plugins: [],
}

I have this code in my page, both buttons look the same:

  <div class="text-center space-x-8">
    <button type="button" class="py-2 px-4 bg-green-500 text-white font-semibold rounded-lg shadow-md hover:bg-green-700 focus:outline-none disabled:opacity-50" tabindex="-1">
      Submit
    </button>
    <button type="button" class="py-2 px-4 bg-green-500 text-white font-semibold rounded-lg shadow-md disabled:opacity-50" disabled tabindex="-1">
      Submit
    </button>
  </div>

I already re-compiled my code and deleted all my browsers caché, but it still does not work. Do I have to do anything else for this to work?

like image 252
Alejo Dev Avatar asked Nov 23 '20 03:11

Alejo Dev


People also ask

How do I make a button disabled?

The disabled attribute is a boolean attribute. When present, it specifies that the button should be disabled. A disabled button is unusable and un-clickable. The disabled attribute can be set to keep a user from clicking on the button until some other condition has been met (like selecting a checkbox, etc.).

How do you use the last child in tailwind?

Just use last:${yourClassName} to target the last child in your case. Even though the other answer, this answer now points to the best way to do first/last child selection.

What is variant in Tailwind CSS?

The variants section of your tailwind.config.js file is where you control which variants should be enabled for each core plugin: // tailwind.config.js module. exports = { variants: { extend: { backgroundColor: ['active'], // ...

How do I configure which utility variants are enabled in tailwind?

Configuring which utility variants are enabled in your project. The variants section of your tailwind.config.js file is where you control which variants should be enabled for each core plugin:

What's new with tailwind CSS?

Here's the link: Upgrade Guide -Tailwind CSS It will change other things that you might want to be aware of. Show activity on this post. It's now possible to enable all variants by default with the new just in time (JIT) compiler. No need to update your Tailwind config file every time you want to add a new variant.

Do I need to update my tailwind config file every time?

No need to update your Tailwind config file every time you want to add a new variant. 1. Upgrade to TailwindCSS 2.1 or later 2. Enable JIT mode in your config

How to apply a class conditionally in tailwind?

Every utility class in Tailwind can be applied conditionallyby adding modifier to the beginning of the class name that describes the condition you want to target. For example, to apply the bg-sky-700class on hover, use the hover:bg-sky-700class:


1 Answers

I found the solution by using play.tailwindcss.com:

This is the syntax I have to use in the tailwind.config.js file:

module.exports = {
  purge: [],
  theme: {
    extend: {},
  },
  variants: {
    opacity: ({ after }) => after(['disabled'])
  },
  plugins: [],
}
like image 53
Alejo Dev Avatar answered Oct 21 '22 00:10

Alejo Dev