Closed bkyerv closed 8 months ago
same here, on a brand new Tauri project with Vite React, Dark mode is not working.
I have the same issue with Radix and Vite as well. I just started a project with the react-ts vite template and added Radix Themes. Every other theme configuration works properly except for appearance which does nothing and defaults to light.
main.tsx
import React from 'react'
import ReactDOM from 'react-dom/client'
import { Theme } from '@radix-ui/themes'
import App from './App.tsx'
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<Theme
appearance='dark'
accentColor='violet'
grayColor='mauve'
panelBackground='translucent'
radius='small'
>
<App />
</Theme>
</React.StrictMode>,
)
vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
})
Here's a solution using https://usehooks-ts.com/react-hook/use-dark-mode:
document.body.classList.toggle('dark', isDarkOS);
to the hook's logic. It can be anywhere as long as it's outside of the useEffect.Theme
component is rendered, import your new hook, and edit as follow:
function App() {
const { isDarkMode } = useDarkMode();
return (
<Theme
appearance={isDarkMode ? 'dark' : 'light'}
>
// etc...
There are some "hacks" to fix this. Check out issue #22 .
Resume: <body class="dark">
@bkyerv I've documented the potential issue your facing in #22 with this comment
However, there is no way to assess your problem as you didn't even bother providing a description