nextui icon indicating copy to clipboard operation
nextui copied to clipboard

Themes don't working with dark mode switcher

Open eder3232 opened this issue 2 years ago • 6 comments

NextUI Version

2.2.9

Describe the bug

when you add new theme for example purple-dark (example provied by documentation):

import type { Config } from 'tailwindcss'
const { nextui } = require('@nextui-org/react')

const config: Config = {
  content: [
    './src/pages/**/*.{js,ts,jsx,tsx,mdx}',
    './src/components/**/*.{js,ts,jsx,tsx,mdx}',
    './src/app/**/*.{js,ts,jsx,tsx,mdx}',
    './node_modules/@nextui-org/theme/dist/**/*.{js,ts,jsx,tsx}',
  ],
  theme: {
    extend: {},
  },
  darkMode: 'class',
  plugins: [
    nextui({
    
      themes: {
        'purple-dark': {
          extend: 'dark', // <- inherit default values from dark theme
          colors: {
            background: '#0D001A',
            foreground: '#ffffff',
            primary: {
              50: '#3B096C',
              100: '#520F83',
              200: '#7318A2',
              300: '#9823C2',
              400: '#c031e2',
              500: '#DD62ED',
              600: '#F182F6',
              700: '#FCADF9',
              800: '#FDD5F9',
              900: '#FEECFE',
              DEFAULT: '#DD62ED',
              foreground: '#ffffff',
            },
            focus: '#F182F6',
          },
          layout: {
            disabledOpacity: '0.3',
            radius: {
              small: '4px',
              medium: '6px',
              large: '8px',
            },
            borderWidth: {
              small: '1px',
              medium: '2px',
              large: '3px',
            },
          },
        },
      },
    }),
  ],
}
export default config

and add switcher (example provided by documentation):

'use client'

import { useTheme } from 'next-themes'
import { useEffect, useState } from 'react'

export function ThemeSwitcher() {
  const [mounted, setMounted] = useState(false)
  const { theme, setTheme } = useTheme()

  useEffect(() => {
    setMounted(true)
  }, [])

  if (!mounted) return null

  return (
    <div className="flex flex-col">
      The current theme is: {theme}
      <button onClick={() => setTheme('light')}>Light Mode</button>
      <button onClick={() => setTheme('purple-dark')}>Dark Mode</button>
    </div>
  )
}

on the first click the "theme" (variable) changes from "light" to "purple-dark", and colors too, but in the next click, when you try to change from "purple-dark" to "light", the "theme" (variable) changes, but the colors don't, Even though the "theme" changed to light, the colors still maintain the purple-dark style

Your Example Website or App

https://github.com/eder3232/nextui-issue

Steps to Reproduce the Bug or Issue

npm run dev

Expected behavior

when the theme changes to light, the colors are supposed to change to light

Screenshots or Videos

https://github.com/nextui-org/nextui/assets/76524247/5735c995-f25c-4e74-997d-07d22be90e76

Operating System Version

windows

Browser

Chrome

eder3232 avatar Dec 10 '23 00:12 eder3232

I just had the same problem, try to add the name of your new theme in the NextThemesProvider:

<NextThemesProvider attribute="class" defaultTheme="dark" themes={['dark', 'light', 'purple-dark']} >

I hope it works for you! @eder3232

JosePadilla98 avatar Jun 09 '24 06:06 JosePadilla98

I have the same problem too - nearly a year later :-(

partridgeworks avatar Nov 15 '24 16:11 partridgeworks

@partridgeworks can you share a latest sandbox for us? In next version, we will have a new theme hook.

wingkwong avatar Nov 16 '24 03:11 wingkwong

I have the same issue in 2025. No updates? @JosePadilla98 This didnt work for me either

Jay-ArBrouillard avatar Mar 06 '25 20:03 Jay-ArBrouillard

@Jay-ArBrouillard can you share a sandbox?

wingkwong avatar Mar 07 '25 02:03 wingkwong

closing - inactivity

wingkwong avatar Dec 14 '25 07:12 wingkwong