tailwindlabs / discuss

A place to ask questions, get help, or share what you've built with Tailwind CSS.
MIT License
171 stars 9 forks source link

Multiple psuedo selectors #467

Open jaredmeakin opened 4 years ago

jaredmeakin commented 4 years ago

Trivial example, but how would one enable variant support for multiple pseudo selectors?

.button:hover:enabled {
   cursor: pointer;
}

.button:hover:disabled {
   cursor: not-allowed;
}

Thanks!

cytRasch commented 4 years ago

You can achieve this by writting yout own little plugin:

const plugin = require('tailwindcss/plugin')

module.exports = {
    theme: {
        extend: {},
    },
    variants: {},
    plugins: [

        plugin(function({ addComponents }) {

            const extendedButtons = {
                '.button': {
                    '&:hover': {

                        '&:disabled': {
                            cursor: 'not-allowed'
                        },

                        '&:enabled': {
                            cursor: 'pointer'
                        }
                    }

                },
            }
            addComponents(extendedButtons)
        })
    ],
}

This will auto-create your css with this variant-concatination.