Component missing dark mode feature

I recently started using the Dropdown component from NextUI and managed to set up the dark mode based on the Dark mode documentation.

However, when I implemented the Dropdown, it appeared in the light theme instead of the dark mode that I had configured:

https://i.sstatic.net/0VFtOQCY.png

Here is the code snippet where I tried to apply the dark mode:

// app/layout.tsx

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <React.StrictMode>
      <html lang="en">
        <body className={inter.className}>
          <NextUIProvider>
            <main className="dark text-foreground bg-background min-h-screen p-4 md:p-24">
              <Header />
              {children}
              <Footer />
            </main>
          </NextUIProvider>
        </body>
      </html>
    </React.StrictMode>
  );
}

Next, I tried to create a dark-themed dropdown as follows:

// app/_components/nav.tsx

export default function Nav() {
  
  return (
    <Card className="mb-5 p-0">
      <CardBody className="flex flex-row py-3 px-4 w-full">
        <div className="flex flex-auto flex-row space-x-4 ">
          ... some buttons ...
        </div>
        <div className="flex flex-auto flex-row-reverse">
          <div className="flex items-center gap-4">
            <Dropdown
              backdrop="blur"
              showArrow
              radius="sm"
              classNames={{
                base: "before:bg-default-200", // change arrow background
                content: "p-0 border-small border-divider ",
              }}
            >
              <DropdownTrigger>
                <Button variant="ghost">Open Menu</Button>
              </DropdownTrigger>
              <DropdownMenu>
                <DropdownItem>View</DropdownItem>
              </DropdownMenu>
            </Dropdown>
          </div>
        </div>
      </CardBody >
    </Card >
  )
}

However, the Dropdown still appeared in white, whereas I wanted it in black:

https://i.sstatic.net/82ml57ZT.png

Edit (26th August): Upon @xxnikosxx's suggestion, I tried directly adding the ´dark´ class to the components, which worked:

I applied the class dark to the Dropdown, DropdownMenu, and DropdownItem:

export default function Nav() {

  return (
    <Card className="mb-5 p-0">
      <CardBody className="flex flex-row py-3 px-4 w-full">
        <div className="flex flex-auto flex-row space-x-4 ">
          <!-- ...some buttons... -->
        </div>
        <div className="flex flex-auto flex-row-reverse">
          <div className="flex items-center gap-4">
            <Dropdown
              radius="sm"
              classNames={{
                content: "dark text-white p-0 border-small border-divider ", // here
              }}
            >
              <DropdownTrigger>
                <Button variant="ghost">Open Menu</Button>
              </DropdownTrigger>
              <DropdownMenu className="dark">                               // here
                <DropdownItem className="dark">View</DropdownItem>          // here
              </DropdownMenu>
            </Dropdown>
          </div>
        </div>
      </CardBody >
    </Card >
  )
}

Now, the Dropdown appears correctly in dark mode as shown in the docs: https://i.sstatic.net/XIP6qusc.png

Answer №1

Sharing the solution that proved effective during discussions - add .dark to the components directly to enable dark mode exclusively. In case you wish to implement both light and dark modes, utilize .dark: to alter class names for dark mode specifically.

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

Angular - the ngFor directive causing function to be executed repeatedly

I need help with a template: <mat-card *ngFor="let cargo of cargos" class="cont-mat"> ... <mat-checkbox *ngFor="let truck of (retrievingTrucksByUserIdAndRules(cargo.id) | async)" formControlName="truckId" ...

Encountering a MODULE NOT FOUND error when using express.js

const express = require("express"); const app = express(); const path = require("path"); app.use(express.static(staticPath)); let staticPath=path.join(__dirname, ".."); There seems to be an error in these lines of ...

Manipulating JSON with ng-model in AngularJS

Let's say I have a simple JSON similar to this: { "Object 0": {} } I am trying to display it as a tree structure. This is the approach I am taking: <span>{{key}}</span> // Object 0 <span>{{value}}</span> // {} <ul> ...

Issue occurs when nested functions prevent the data() variable from updating

As a newcomer to VUE, I may not be using the right terminology so bear with me. I'm attempting to update a variable that is defined in the script tag's "data()" function. The issue arises when trying to change the value of a variable within the ...

Angular 2 is not recognizing the element 'router-outlet'

I am currently utilizing universal-cli... This is how my app.node.module.ts appears: /** * This file and `main.browser.ts` are quite similar, for now! * By separating these, you can create logic, imports, etc that are "Platform" specific. * If you wis ...

The Error Message: "404 Not Found - Your Form Submission Could Not

Greetings, I am currently immersing myself in learning NodeJS and the Express framework. However, I have encountered an issue when attempting to submit a form that is supposed to go to the '/users/register' URL. It appears that my app.js is unabl ...

Enhancing Values Across a Timeframe Using JavaScript

Last time, I asked about my code. Here is what I have currently: var secs = 100; setInterval(function() { var $badge = $('#nhb_01'); $badge.text((parseFloat($badge.text())+0.01).toFixed(2)); }, secs); I want the counter to increase by ...

The datatable fails to render after executing a function in AngularJS

When I load the page without calling a function, the data is displayed in a datatable perfectly fine. However, if I try to generate the datatable after calling a function, it does not work. HTML: <div class="widget-body no-padding"> ...

How can we send state updates directly to a conditionally rendered React component?

I am currently developing a React application with a tab section that displays specific components upon clicking on a tab. Initially, I have my parent component: class Interface extends Component { constructor(props) { super(props); ...

Retrieving information from a React form and sending it to an Express.js server

I am currently attempting to transfer data from a React form to Express.js using POST. I have included some axios code in my React code, but I am uncertain if it is necessary. At the moment, my goal is to simply log the form data in Express.js, but I am e ...

Changing the formatting of a buffer from int8 to float32 using JavaScript

Within a buffer, I have a series of bytes that were read from a file. I am looking to convert these bytes into a sequence of float32 values without having to copy them to a new buffer, given that each data block is approximately 15KB in size. I have come a ...

Utilizing Vue.js to incorporate the isActive property to the class name within a v-for loop, along with implementing dynamic class names

I am currently using a loop to iterate through some data in my store.js file, and everything is functioning as expected. However, I would like to add a condition to check if the Vue instance is active before applying a specific class to the polygon element ...

Utilize Material-UI slider components to dynamically manage slider handles

I am trying to dynamically create sliders based on user input and struggling with saving values when they are changed. Below is the code snippet I have implemented so far. The issue I'm facing is that I cannot retrieve the value using event.target.val ...

What are some methods for controlling a webpage? Is it through HTML, JavaScript, Xpath, or

Hey there, I could really use your expertise on untangling a question that has me completely stumped. What exactly is the mechanism for controlling a webpage? a. HTML b. JavaScript c. Xpath d. CSS ...

Tips for creating a navigation bar item that displays a component depending on its active state

Trying to enhance the modularity of my code but facing difficulties. I have a tab bar and I want to render a specific component based on the clicked nav/tab item. Struggling with passing props properly, as the current code only recognizes the children valu ...

When utilizing Ionic Firebase, the user profile saved in the sidemenu is stored using the Events class. However, the saved profile disappears as soon as

Hello there. I am currently working on displaying my user's information in the sidemenu, and after some research, I found that using the Events class might solve this issue. However, I have noticed that the data saved in subscribe gets destroyed whene ...

Verify whether the initial value is distinct from the subsequent one using AJAX

I'm currently working on a project where I need to compare the first value received from an AJAX call to the subsequent values. However, I seem to be stuck and unable to figure out how to achieve this. Every 5 seconds, I am checking the follower count ...

Incorporating Google font into Bootstrap using Next.js

I want to load a Google font following the instructions outlined here: https://nextjs.org/docs/basic-features/font-optimization When I follow the documentation and load it like this, everything works fine: import { Open_Sans } from '@next/font/google ...

Issue with Vue JS function not providing the desired array output

I declared a property in my data model like this: someArray: [] A function returns an array: getMyArray: function (someId) { var result = [7, 8, 9, 10]; return result; } I'm assigning the result of the function to m ...

Tips for including markdown content within components in MDX files

I'm currently in the process of utilizing MDX pages along with React components for a project. My issue lies in wanting to generate HTML when adding text inside a component, similar to how it works with content outside of components. However, I'v ...