The applied style of NextUI Components may be inconsistent, appearing to not apply in certain instances even though it does work

I've hit a roadblock trying to solve this issue. While using NextUI, I've managed to successfully apply styles to some components like the navbar, indicating that I have correctly installed NextUI and configured Tailwind. However, I'm facing difficulty in getting the style to apply to NextUI modals and inputs.

Below is my Tailwind configuration:

module.exports = {
  content: [
    "./app/**/*.{js,ts,jsx,tsx,mdx}", 
    "./pages/**/*.{js,ts,jsx,tsx}",
    "./components/**/*.{js,ts,jsx,tsx}",
    "./node_modules/@nextui-org/**/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

Here's the component where I'm encountering styling issues with NextUI components:

import {
  Modal, 
  ModalContent, 
  ModalHeader, 
  ModalBody, 
  ModalFooter, 
  Button, 
  Input
} from "@nextui-org/react";
import { useState } from "react";

function LoginModal(props) {
  const [emailValue, setEmailValue] = useState('')
  const [passwordValue, setPasswordValue] = useState('')
  const [errorMessage, setErrorMessage] = useState([])

  return (
    <Modal 
      isDismissable={false} 
      isKeyboardDismissDisabled={true}  
      backdrop="opaque" 
      className={{
        backdrop: "bg-gradient-to-l from-zinc-800 to-zinc-900/10 backdrop-opacity-20"
      }}
      hideCloseButton={true}
      defaultOpen={true}
      >
      <ModalContent>
        {(onClose) => (
          <>
            {errorMessage && errorMessage.map(error => {
              return <h1 className=" text-red-800 font-sans">{error}</h1>
            })}
            <ModalHeader className="font-sans">Admin Connection</ModalHeader>
            <ModalBody>
              <div className="flex w-full flex-wrap md:flex-nowrap mb-6 md:mb-0 gap-4">
                <Input 
                  type="email" 
                  label="Email" 
                  variant="flat"
                  onValueChange={setEmailValue}
                  value={emailValue}
                  isInvalid={errorMessage ? true : false}
                />
              </div>

              <Input 
                type="password" 
                label="Password"
                variant="underlined"
                onValueChange={setPasswordValue}
                value={passwordValue}
                />
            </ModalBody>
            <ModalFooter>
              <Button onPress={async () => {
                const response = await fetch('http://localhost:3000/users/adminLogin', {
                  method: 'POST',
                  headers: {
                    "Content-Type": "application/json",
                  },
                  body: JSON.stringify({
                    email: emailValue,
                    password: passwordValue
                  })
                })

                const data = await response.json();

                if (data.result) {
                  props.setIsAdmin(true);
                  onClose();
                } else if (data.result === false) {
                  const tmpArrayOfErrors = []
                  tmpArrayOfErrors.push(data.message)
                  setErrorMessage(tmpArrayOfErrors)
                } else if (!data.result) {
                  for (let i = 0; i < data.errors.length; i ++) {
                    const tmpArrayOfErrors = []
                    for (const index in data.errors) {
                      tmpArrayOfErrors.push(data.errors[index].msg)
                    }
                    setErrorMessage(tmpArrayOfErrors)
                  }
                }
              }}>
                Log in
              </Button>
            </ModalFooter>
          </>
        )}
        
      </ModalContent>

    </Modal>
  )
}

export default LoginModal

Here's my global.css file:

@tailwind base;
@tailwind components;
@tailwind utilities;

@font-face {
  font-family: "Romantic";
  src: url('../fonts/romantic-font-2-1715585786-0/ssromantic.otf');
}

body {
  padding: 0;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
    Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
  width: 100vw;
  height: 100vh;
  font-family: "Romantic";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  background-color: #E6E6FA;
}

* {
  box-sizing: border-box;
}

Would appreciate any assistance with this matter :)

Thank you!

Answer №1

Issue :

Struggling to customize NextUI Modal and Input component with custom styling

Cause :

Mistakenly used backdrop key instead of classNames in Modal prop, along with improper tailwind configuration.

Resolution :

To personalize NextUI components, always refer to the component's props first, check the available keys that can be passed to the classNames prop.

In your tailwind.config.js, update the plugins key (check 1):

plugins: [nextui()]

Make changes to Modal Props (refer 4 5 6):

<Modal 
    isDismissable={false} 
    isKeyboardDismissDisabled={true}  
    backdrop="opaque" 
    classNames={
        {
            backdrop: "bg-gradient-to-t from-zinc-900 to-zinc-900/10 backdrop-opacity-20"
        }
    }
    hideCloseButton={true}
    defaultOpen={true}
>

Apply similar modifications for <Input/> (refer 2 3) and review the keys passed in classNames.

Regarding Font Usage :

I recommend reading and implementing the font optimization strategies if desired.

NextJS offers options for importing local/custom fonts. Check out the links below (refer 7 8).


Further References :

  1. Setup :
  2. Custom Styles (Input) :
  3. Input Props : https://nextui.org/docs/components/input#input-props
  4. Custom Styles (Modal): https://nextui.org/docs/components/modal#custom-styles
  5. classNames (Modal Props) : https://nextui.org/docs/components/modal#modal-props
  6. Custom Backdrop : https://nextui.org/docs/components/modal#custom-backdrop
  7. Font Optimization : https://nextjs.org/docs/app/building-your-application/optimizing/fonts
  8. Importing Custom/Local fonts : https://nextjs.org/docs/app/building-your-application/optimizing/fonts#local-fonts

If this solution resolved your issue, kindly mark it as solved. Feel free to upvote if it was helpful. For any queries, please leave a comment (I will update the answer accordingly).

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

How can I effectively vertically position a button in Bootstrap 5 without compromising its functionality?

I'm attempting to reposition the sign-up buttons for Google, Apple, and email below where it says "join," but they stubbornly refuse to budge even when I try to force them with CSS. https://i.sstatic.net/74LQk.jpgCSS .homepage_topRight_Buttons{ ...

Having trouble extracting data from Moz Bar through selenium using Python?

Having trouble retrieving the spam score from Moz bar using Selenium WebDriver? I've attempted various methods such as XPath, class, and tag name without success. Any assistance would be greatly appreciated: from selenium.webdriver.common.by import By ...

Tips for positioning a chat box at the bottom of a v-card's visible area

My goal is to create a chat app using Vuejs 3 and Vuetify 3, but I'm encountering an issue aligning the chatbox with the v-card component. Instead of being positioned at the bottom of the v-card, the chatbox (green) appears at the bottom of the page. ...

Other elements are unable to conceal Material UI InputBase

Displayed below is a navigation bar that sticks to the top, followed by rows of InputBase components from material-ui. Despite setting the background color of the nav bar to white, the input always appears above the nav. This strange behavior stopped when ...

The Tailwind fixed tabs navigation feature prevents scrolling

I recently implemented some fixed tabs on one of my web pages. By making the tabs fixed, users can now smoothly scroll down each tab page without having to move the navigation tabs. Prior to fixing the tabs in place, I was able to scroll horizontally thr ...

Utilize an icon within an input box using content and the :before pseudo-element instead of relying on

My problem is that I have a great font set up and I use it to add custom icons next to my buttons. (for example: check here) Now, I want to create an input box and place an icon before it like in this guide HERE Instead of using a background image, I wou ...

Chrome glitch: how to make radio buttons bigger

Hey there! I'm having a little trouble trying to increase the size of my radio button using this CSS code. It seems to work in Mozilla, but not in Chrome. .rdo { margin: 1em 1em 1em 0; transform: scale(1.3, 1.3); -moz-transform: scale(1.3, 1.3); -ms- ...

Manipulating parent based on first child using CSS

Is it possible to manipulate the parent element using CSS based on the presence of a specific child? For instance, I want to style a table cell differently if the first child within it is a link. <td>Hello</td> <td><a href="go.html"& ...

Ensure that Mathjax underscores are consistent with the height of other characters

Presented below is the latex code being used with Mathjax. \class{mathjaxCursor}{\text{_}} ...and here is the accompanying css: .mathjaxCursor { font-weight: bold; background-color: red; } This setup results in the following display: ...

Folded Corner Div using only CSS

I've been tirelessly experimenting with countless online methods, but I can't seem to make anything work. There's a div that needs to be flexible in width and height, positioned on a tile-able background image with a 1px border. The challe ...

Obtain the computed style by utilizing setTimeout for effective functionality

I want to retrieve the calculated style (background-color) of a span element. Here's my HTML code, consisting of two label elements, each containing an input and a span: <label> <input type="radio" name="numbers" value="01" checked/> ...

How can I show the configuration in Laravel?

After updating my pages to utilize an extended header for consistent content across all pages, I encountered an issue with the footer configuration. Whenever I attempt to retrieve a configuration from Laravel, it appears as normal text instead of being pro ...

creating a vertical scroll bar for an HTML table's content

How can I set a fixed height for my HTML table on a webpage so that if it exceeds the height, a vertical scrolling bar is automatically displayed? Any assistance would be greatly appreciated. Thank you. ...

Can the color scheme be customized for both light and dark themes in Ant Design version 5?

After creating a hook that successfully toggles between light and dark modes in Chrome's Rendering panel, I noticed that the values in the ConfigProvider remain unchanged when switching themes. Can anyone suggest a workaround to modify the design toke ...

Dynamically change the fill color of an SVG using styled-components

I've been attempting to target the fill property of my SVG using CSS in styled-components without any luck. Here is my SVG: <svg width="65" height="19" viewBox="0 0 65 19" fill="none" xmlns="http://www. ...

Achieving a transparent inner box-shadow effect on hover: a step-by-step guide

Is there a way to make the black ring transparent upon hover by changing box-shadow: 0 0 0 5px #000, 0 0 0 10px green to box-shadow: 0 0 0 5px transparent, 0 0 0 10px green? It doesn't seem to be working for me. Any suggestions on how to achieve this ...

On three out of five pages, Mozilla Firefox and Internet Explorer are causing extra spacing in my navigation section, yet not on every page

I've been troubleshooting my website and can't seem to pinpoint the issue. I have 5 pages all connected to the same CSS file and created in a consistent manner. Interestingly, Safari, Chrome, and Opera display everything correctly. However, in Fi ...

Error: The reference property 'refs' is undefined and cannot be read - Next.js and React Application

Here is my code for the index page file, located at /pages/index.js import { showFlyout, Flyout } from '../components/flyout' export default class Home extends React.Component { constructor(props) { super(props); this.state = {}; } ...

Issues arise with the Dropend Menu in Bootstrap when attempting to utilize a dropdown menu

As I work on developing a sidebar using Bootstrap 5, I encountered an issue with the positioning of a "Dropdown" and "Dropend" menu when they are open. Specifically, while the Dropdown menu functions correctly, the Dropend menu does not align properly. In ...

What is the best way to retrieve the border-color inline style using jQuery?

I have a HTML tag like this. <span id="createOrderFormId:accountNo" style="border-color: red;"><</span> To retrieve the style value for the border-color property, I tried using the following jQuery code: $( document ).ready(function() { ...