The Radix UI Theme's dark mode isn't taking effect

I'm having trouble getting the dark mode to work properly in my Radix UI app. Despite setting appearance="dark", nested components like Box and Card remain light.

Interestingly, other props such as accent color seem to be working fine. It's just the dark mode that's causing issues.

Here's the code snippet:

import { Grid, Theme } from '@radix-ui/themes';
import '@radix-ui/themes/styles.css';
import './App.css';


function App() {
  return (
    <Theme appearance="dark" accentColor="ruby" radius="large">
      <Grid columns="1" rows="2" align="center">
        <FirstComponent />
        <SecondComponent />
      </Grid>
    </Theme>
  );
}

export default App;

Answer №1

Unfortunately, I'm experiencing the same issue. Despite following the guidelines outlined in the RadixUI Dark Mode Docs, it seems that dark mode is not functioning properly. A quick glance at the open issues related to dark mode on their Github page reveals that this is a common problem. Even with the recent release of version 2.0.0, the issue persists from version 1.1.2. At this time, I don't have a solution to offer, but I will keep you updated if I come across one.

Note: One of the Github issues suggests a workaround of enabling dark mode permanently by adding the dark class to the <body> element:

<body class="dark">
. While this can be toggled using vanilla JS (or a library like React), it may be considered more of a temporary fix rather than a long-term solution.

Answer №2

An innovative solution that just occurred to me involves creating a function that can add or remove the class "dark" from the HTML body. Simply include the following function in an onClick event and you'll see your issue resolved.

const [darkMode, setDarkMode] = useState<boolean>(false);

const toggleDarkMode = () => {
  setDarkMode(!darkMode);
      if (darkMode) {
        document.body.classList.remove("dark");
       } else {
        document.body.classList.add("dark");
     }
  };

Answer №3

To implement a dark theme, insert the code snippet below into your index.html file:

<html lang="en" class="dark-theme">

You can easily switch between appearance="light" and appearance="dark" using this setup.

Answer №4

Swap out the appearance="dark" attribute for appearance="inherit"

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for creating seamless page transitions in Material UI

Looking to create seamless page transitions with the help of Material-UI's <Slide> component while working with the Modernize Free React MUI Dashboard. Below is a snippet from my current code. import React from 'react'; import { Brow ...

What is the best way to extract a number from a string in JavaScript?

There are instances in HTML files where a <p> tag displays the price of a product, such as ""1,200,000 Dollar"". When a user adds this product to their cart, I want the webpage to show the total price in the cart. In JavaScript, I aim to e ...

Issue with Fluid Square Divs and Box-Sizing

I'm currently working on creating a responsive fluid div that maintains its square shape as the page is resized. I've come across a method that involves using the following CSS code: div{ width:25% padding-bottom:25%; } However, it seem ...

To create a distinctive design, the HTML5 wrapper will specifically enclose the Header element

After using a border, I discovered that my wrapper is only wrapping the header and not extending down to the footer. Can anyone offer some guidance on how to wrap the entire content from the header to the footer? I've come across suggestions to speci ...

Both position absolute and position relative are failing to work effectively

Whenever I click on a div called "test", another div named "outside" appears, along with a div named "inside" that has a higher z-index. The problem arises when I try to set the position of "inside" to absolute, as I am unable to assign a margin-bottom. A ...

What is the best way to arrange a bootstrap .container?

I've been struggling to position a content DIV on a bootstrap carousel, but so far I haven't been successful in figuring it out. Below is a screenshot of the current output from my code, which is not what I am aiming for. What I'm trying t ...

Trouble linking jQuery file to HTML page

While working on a project, I stumbled upon a code that I am editing. You can find the original code here: However, when I try to link the .js file, it fails to load properly and displays a single large image instead of a carousel of images. Thank you fo ...

What is the best way to send data between pages in a React application?

After solving the question, I can confirm that the code lines are correct. By utilizing console log, I verified that all parameters are being passed correctly: I am creating a website to showcase my personal projects, using components across different pag ...

Creating dynamic dxi-column with different data types in dxDataGrid

Our team is currently working on an angular application that involves displaying records in a dxdatagrid. The challenge we are facing includes: Different schema each time, with data coming from various tables. The need to add/edit records. Displayi ...

Is it possible to use a single function to both set the state and return JSX?

I'm currently grappling with creating a function that, when called, will update the state to an object {item: 'whatever the user types', list: [...list, todo]}. The challenge I'm facing is figuring out how to update the state and return ...

Adjust the margin-top based on the height of another element

I'm facing an issue with two fixed navbars positioned one under the other. I used the 'fixed-top' class to fix both at the top, but the margin-top I added to make them align is not responsive. Is there a way to make the margin-top responsiv ...

Getting the canonical URL for dynamic pages in NextJS. How can it be done?

Previous to nextjs 9.4, I relied on the next-absolute-url package to provide the origin in getInitialProps. With Next.js 9.5 and the implementation of Automatic Optimization, using getServerSideProps and getStaticProps is preferred. Unfortunately, the nex ...

What steps can be taken when encountering TS errors regarding missing required fields that are in the process of being filled?

In a typical scenario, the process involves creating an empty object and populating it with the necessary data. Initially, this object does not contain any properties, which leads to TypeScript flagging an error since it lacks the required type. For insta ...

Adjust font size using jQuery and CSS styles

I'm currently working on a website where the body has a specified font-size property that is inherited by all elements on the page. Some tags on the page have font-sizes specified in percentages (%). Others are assigned sizes in pixels (px). I&apos ...

Develop a unique element in EditorJs

I have integrated the EditorJs plugin into my react js application: import ReactDOM from "react-dom"; import React, { Component } from "react"; import EditorJs from "react-editor-js"; import { EDITOR_JS_TOOLS } from "./constants"; class ReactEditor e ...

Having trouble configuring bcryptjs in a React.js project

I have been working on setting up a single registration page within a react component. However, I encountered an issue when trying to hash the password before sending the response to my back-end. I am puzzled as to why the code snippet below is not functi ...

Using Jquery variables for calculations and they do not work with numerical values

Hey there, I'm new to this so bear with me. I have a jQuery question that's puzzling me... I'm attempting to set the line height using the following method: var line_height = $('.container').css("height"); console.log(line_height ...

An internal issue has occurred: RangeError: The call stack limit has been exceeded in Next.js React

Recently, I've encountered the error message "⨯ Internal error: RangeError: Maximum call stack size exceeded" and I'm struggling to pinpoint the root cause of this issue. My goal is to have the functionality where clicking the "Add to Cart" but ...

Issue arising from background-image and content property size

.section--7__photos { height: 50vw; max-height: 70rem; margin: 0 8%; background: url("https://ableton-production.imgix.net/about/photo-8.jpg?crop=right&dpr=1.5&fit=crop&h=250&ixjsv=1.1.3&q=66&w=417") no-repeat top 0% center/ ...

Highlighting JavaScript code with React Syntax Highlighter exclusively

I've been struggling to highlight Ruby code, but it seems like no matter what I do, it keeps highlighting JavaScript instead. It's frustrating because I can't seem to get it right. import React from "react"; import atom from "node_module ...