reactjstailwind-cssheadless-ui

Darkmode not working on tailwind headless UI


Darkmode works everywhere in my react app, except on a headless ui combobox. I put a styled h1 in the same component and applied dark:bg-red-200(and any other style) no problem. The combobox accept all other tailwind utilities including attibutes like hover: but not the dark: property.


Solution

  • For others (such as me) stumbling upon this:

    Solution I ended up using:

    I ended up using useEffect to add the dark class to the body:

    useEffect(() => {
      if(darkMode){
        document.body.classList.add('dark')
      }else{
        document.body.classList.remove('dark')
      }
    }, [darkMode])