tailwindcss-custom-forms icon indicating copy to clipboard operation
tailwindcss-custom-forms copied to clipboard

Disabled states

Open MartijnCuppens opened this issue 4 years ago • 13 comments

We should provide some basic theming for the :disabled state. Probably a color setting which will be applied as background.

MartijnCuppens avatar Jul 15 '19 19:07 MartijnCuppens

What about readonly?

hacknug avatar Jul 16 '19 15:07 hacknug

I've been messing with the disabled state for a checkbox and having a hard time to change the icon from white to a dark gray from my Tailwind theme. Hoping to see if someone else can figure that out.

barryofguilder avatar Jul 25 '19 14:07 barryofguilder

Colorizing the check will be harder indeed since it's actually a background-image.

Other than that: should we use a disabled state per component (which is more flexible but is harder to keep in sync between components) or do we use a global disabled background-color, ect (which will require to merge the disabled theming with the components here:)?

https://github.com/tailwindcss/custom-forms/blob/454ba00d5a54deac522b2d68884bf92391136636/src/index.js#L156-L161

MartijnCuppens avatar Jul 25 '19 17:07 MartijnCuppens

As workaround we can define disabled state inside theme config

            default: {
                input: {
                    borderColor: theme('colors.grey.lighter'),
                    borderWidth: '1px',
                    borderRadius: undefined,
                    '&::placeholder': {
                        opacity: '1',
                    },
                    '&:hover': {
                        borderColor: theme('colors.grey.default'),
                        '&:focus': {
                            borderColor: theme('colors.grey.dark'),
                        },
                    },
                    '&:focus': {
                        outline: 'none',
                        boxShadow: undefined,
                        borderColor: theme('colors.grey.dark'),
                    },
                    '&:disabled': {
                        opacity: 0.4,
                    },
                },
            },

Koc avatar Aug 11 '19 20:08 Koc

+1 ^

Config looks like a way to go.

I would say that opacity 0.4 isnt the best choice (especially for those with weaker-contrast screens). Kind of hard to see, when there is a value already, or checkbox is checked for example. I personally use grey bg color.

pavelloz avatar Sep 25 '19 14:09 pavelloz

Did anyone nail down an appropriate way forward for this? Not having a disabled state for checkboxes is kind of a bummer.

lukepighetti avatar Oct 28 '19 23:10 lukepighetti

I'll likely be adding some default disabled styles in the next release but you can always just add utilities to make things feel disabled:

<input type="checkbox" class="form-checkbox opacity-50" disabled>

This is what I do currently on my own projects, never really been a painful problem.

adamwathan avatar Oct 29 '19 01:10 adamwathan

This is how I handled mine in Vue

<button
:disabled="!isFormValid"
:class="{ 'opacity-25 cursor-not-allowed': !isFormValid }"
type="submit"
class="text-white bg-primary font-semibold py-1 px-3 rounded"
>
 <span class="uppercase">Do something</span>
</button>
isFormValid() {
    // return your condition  
},

damisparks avatar Oct 09 '20 13:10 damisparks

I'd like to be able to @apply disabled:text-gray-600 disabled:cursor-not-allowed please :)

richardthombs avatar Jan 14 '21 14:01 richardthombs

Actually looking at the 2.0 documentation it seems that this is possible now, right?

richardthombs avatar Jan 15 '21 11:01 richardthombs

Yes, :disabled is now available here. @adamwathan can this issue be closed?

SandroMaglione avatar Jan 26 '21 15:01 SandroMaglione

The other missing key is disabled placeholder color. Not sure it's supported in tailwindcss as

variants: {
    extend: {
      placeholder: ['disabled']
    }
}

triggers TypeError: variantsValue is not iterable error.

Trying to do disabled:placeholder-gray-400

alexcroox avatar Mar 08 '21 15:03 alexcroox

Yes, this is possible now (using 2.0) : disabled:opacity-25 disabled:cursor-not-allowed

But you must define the appropriate variants

    variants: {
        extend: {
            opacity: ['disabled'],
            cursor: ['disabled'],
        },
    },

mchev avatar Jun 02 '21 10:06 mchev