nuxt-modules / tailwindcss

Tailwind CSS module for Nuxt
https://tailwindcss.nuxtjs.org
MIT License
1.66k stars 180 forks source link

Tailwind css dark class is not working with @nuxt.js/colorMode #756

Closed amirsafaricg closed 10 months ago

amirsafaricg commented 10 months ago

Hi I use the @nuxtjs/tailwind and @nuxtjs/colorMode for my project when trying to use the dark mode I did all the steps in the documentation but what happens is when I read the value with $colorMode.value the colorMode.value is changing with my toggle but my page styling is stuck on the dark mode (since my system prefrence is dark). Is it sth I dont wrong or is there an issue here that needs to be addressed in the bug section ?

ineshbose commented 10 months ago

Can you provide a reproduction of your issue please?

I'm linking the documentation for the two to help you ensure that we're on the right page -

  1. https://color-mode.nuxtjs.org/#tailwindcss
  2. https://tailwindcss.nuxtjs.org/examples/dark-mode
chandlerwilcox88 commented 9 months ago

I'm having a similar issue. I installed the package like the documentation said and it adds the correct classes to the html element. The select toggles the class as well but the dark more is always in light mode.

tailwind.config.js

// import konstaConfig config
const konstaConfig = require('konsta/config');

// wrap config with konstaConfig config
const config = konstaConfig({
  content: [
    './components/*.{js,ts,jsx,vue}',
    './pages/*.{js,ts,jsx,vue}',
  ],
  darkMode: 'class',
  theme: {
    extend: {},
  },
  variants: {
    extend: {},
  },
  plugins: [],
});

nuxt.config.ts

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  devtools: { enabled: true },
  build: {
    transpile: ['konsta'],
  },
  modules: [
    '@nuxtjs/tailwindcss',
    'nuxt-icon',
    '@nuxtjs/color-mode'
  ],
  colorMode: {
    classSuffix: ''
  }
})

pages/index.vue

<template>
  <k-page>
    <select
      v-model="colorMode.preference"
      class="border w-24 h-8 dark:bg-gray-900 dark:text-white dark:border-gray-700"
    >
      <option value="system">System</option>
      <option value="light">Light</option>
      <option value="dark">Dark</option>
    </select>
  </k-page>
</template>
<script setup>
// Tailwind Color-mode module init
const colorMode = useColorMode();
</script>

DOM when selecting dark mode:

Screen Shot 2023-12-12 at 6 59 52 PM
ineshbose commented 9 months ago

I'm having a similar issue. I installed the package like the documentation said and it adds the correct classes to the html element. The select toggles the class as well but the dark more is always in light mode.

tailwind.config.js

// import konstaConfig config
const konstaConfig = require('konsta/config');

// wrap config with konstaConfig config
const config = konstaConfig({
  content: [
    './components/*.{js,ts,jsx,vue}',
    './pages/*.{js,ts,jsx,vue}',
  ],
  darkMode: 'class',
  theme: {
    extend: {},
  },
  variants: {
    extend: {},
  },
  plugins: [],
});

nuxt.config.ts

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  devtools: { enabled: true },
  build: {
    transpile: ['konsta'],
  },
  modules: [
    '@nuxtjs/tailwindcss',
    'nuxt-icon',
    '@nuxtjs/color-mode'
  ],
  colorMode: {
    classSuffix: ''
  }
})

@chandlerwilcox88 are you default exporting the config?