Why is it that the default theme of Material UI lacks any stylization at all?

After experimenting with both Carbon Design for React (@carbon/react) and Material UI (@mui/material) in conjunction with Next.js, I encountered styling issues with the components. While they functioned correctly to some extent, there were noticeable discrepancies. Ultimately, I decided to move away from IBM's Carbon and now face similar problems with @mui:

  • CardHeader is not being displayed.
  • The text color of Typography and buttons remains black despite setting the theme provider to use dark mode.
  • Even though my Sign In button has variant="contained", the contained style does not seem to be applied.

Below is the code snippet:

'use client';

import { useState } from 'react';
import Image from 'next/image'
import { Box, Container, Card, CardHeader, CardContent, TextField, Typography, Button } from '@mui/material';
import { ThemeProvider, createTheme } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';

const darkTheme = createTheme({
  palette: {
    mode: 'dark',
  },
});

export default function Home() {
  const [auth, setAuth] = useState<void>(undefined);
  return (
    <ThemeProvider theme={darkTheme}>
      <CssBaseline/>
      <main className="flex flex-col items-center justify-center w-full h-full">
        <Container>
          <Box>
            {auth == null ? <SigIn setAuth={setAuth}/> : null}
          </Box>
        </Container>
      </main>
    </ThemeProvider>
  )
}

type SigInProps = {
  setAuth: (auth: void) => void,
};

function SigIn({setAuth}: SigInProps) {
  return (
    <Card>
      <CardHeader>
        <Typography variant="subtitle1">Subtitle</Typography>
      </CardHeader>
      <CardContent>
        <div className="flex flex-col gap-4">
          <TextField required id="username" label="Username"/>
          <TextField required id="password" type="password" label="Password" autoComplete="current-password"/>
          <Button variant="contained">Sign in</Button>
        </div>
      </CardContent>
    </Card>
  );
}

Outcome:

https://i.sstatic.net/fDc3i.png

I have also raised this issue on GitHub: https://github.com/mui/material-ui/issues/38901

Answer №1

The problem lies in the way you have integrated Tailwind with MUI. Your application's use of Tailwind's CSS preflight should be swapped out for CSSBaseline. The Tailwind base is introducing styles that clash with MUI (e.g., button colors). You can notice some improvement if you disable the first line in your globals.css file (@tailwind base;).

According to MUI's documentation on Tailwind CSS:

  1. Integrate Tailwind CSS into your project by following the guidelines at https://tailwindcss.com/docs/installation.
  2. Remove Tailwind CSS's preflight so that it aligns with Material UI's preflight using CssBaseline.

Based on what I understand, it seems like you encountered a similar issue with Carbon, but I haven't reviewed how you implemented it.

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

Having trouble sending Props between components within a specific route as I keep receiving undefined values

Here is the code for the initial component where I am sending props: const DeveloperCard = ({dev}) => { return ( <Link to={{pathname:`/dev/${dev._id}`, devProps:{dev:dev}}}> <Button variant="primary">Learn More</Butt ...

How to Retrieve a Document with a Map Field in Firestore

Can someone please guide me on how to access the key-value pair in a field in Firestore using Next.js and specifically for isReferralAvailable? I have a key TESTER1 with a boolean value of true that I would like to display in either a table or just console ...

Can these two arrays be merged together in JavaScript?

Here is the structure of the first array: [ 0:{program: id_1}, 1: {program: id_2} ] Now, let's take a look at the second array: [ 0: [ 0: {lesson: name_1}, 1: {lesson: name_2} ], 1: [ 0: {lesson: name_3} ] ] I am attempti ...

Learning to access dynamic form elements in React NativeUncover the secrets of interacting

I am facing a challenge with dealing with dynamic form elements in my React page. I'm not quite sure what the best approach would be for reading all the input values and storing them to the state, or if there are any other solutions available. Any sug ...

Challenges faced with meta tags while integrating redux-persist into Next.js

I'm currently developing an e-commerce application using Next.js and redux. One challenge I've run into is that when I integrate redux-persist into the app, all meta tags cease to function properly. Below are snippets of the code I am working wit ...

Text within table cells on email appears to be shrinking on Windows Phone devices

Can anyone help me understand why Windows Phone reduces the font size when text is placed within a table cell that isn't at 100% width or nested? Below is a screenshot of a test email template I'm working on. When I sent it to a Windows Phone 8. ...

Set up a single array containing multiple objects in a table, each with its own unique set of keys

I am currently developing an application that retrieves data from one or multiple databases, each with different names and varying numbers of columns. The goal is to consolidate this data into a single report screen and export it as a table. While the tabl ...

Tips for Properly Positioning Floating Pop-Up Messages Using CSS and jQuery

I was experimenting with adding a button that triggers a popup message to my website. I followed a coding tutorial using jQuery and CSS, which looks like this: Javascript : !function (v) { v.fn.floatingWhatsApp = function (e) {...} }(jQuery); CSS : .fl ...

Creating a CSS path that incorporates two conditions simultaneously

I'm currently facing a challenge with finding the CSS path in this scenario: There are over 20 child nodes, and I need to identify every node that has fill attribute not equal to none. I understand that I can target a specific node using :nth-child( ...

While continuing to input text, make sure to highlight a specific element from the search results list

Currently, I am using a customized search feature in my React.js application. I am looking for a way to focus on an element within the search results so that I can navigate using arrow keys. At the same time, I need to keep the input field focused to conti ...

Tips on adjusting the scrollbar color with CSS

Check out my jsfiddle here I am attempting to modify the color of the scrollbar, but unfortunately it is not working as expected. This is the CSS code I am using: .flexcroll { scrollbar-face-color: #367CD2; scrollbar-shadow-color: #FFFFFF; ...

Why is my event.target.value not updating correctly in React useState?

My problem is that when I use useState, I am receiving incorrect numbers For example, if I print e.target.value it might display 1, but my selectedIndex shows 2. Similarly, when I have a selectedIndex of 0, it retrieves something different like 1. Any tho ...

Is it considered poor practice to modify a Bootstrap class in Bootstrap 4?

For instance: form-control appears like this Would it be considered inappropriate if I incorporate this scss code? .form-control { -webkit-transition: all 0.30s ease-in-out; -moz-transition: all 0.30s ease-in-out; -ms-transition: all 0.30s ea ...

Error in TypeScript: The type 'Color' cannot be assigned to the type '"default" | "primary" | "secondary"'

Currently, I am utilizing MUI along with typescript and encountering the following issue. It seems like I may be overlooking a fundamental concept here but unfortunately cannot pinpoint it. Error: Type 'Color' is not assignable to type '&quo ...

What are the advantages of incorporating class styles into a material-ui React component design?

While working on a React website, I am exploring the use of the material-ui component. It seems that material-ui recommends placing styles in components' classes property for easier implementation. Each component can then utilize className={...} to ap ...

I would like to add an underline below the title

.thumb-text { position: absolute; width: fit-content; left: 50%; transform: translateX(-50%); } .thumb-text h3 { font-family: Georgia; font-size: 30px; color: black; font-weight: 900; } .thumb-text h3::after { content: ''; p ...

Creating adaptive paper with Material-UI

I'm in the process of developing an application and currently focusing on creating a responsive login page. I want the login elements to be centered both horizontally and vertically, but 'justify-content: center' doesn't seem to work as ...

Utilizing the text field feature within Twitter Bootstrap 3.0 in-line styling

I am attempting to create a horizontal form with an inline text field split into two sections: one on the left and one on the right. The left side will contain horizontal text fields, some of which are inline, while the right side will have a mix of inline ...

How to horizontally align Material-UI elements in ReactJS

My goal is to create a user-friendly form where respondents can input answers to questions and select one as the preferred option by using a radio button. However, I'm facing an issue where Material-UI displays each element on its own line. This is t ...

Tips for adjusting the format of mui datepicker to 'mm-Mon-yyyy'?

While using material-ui, I encountered a problem with changing the date format for the in-library date picker. In an attempt to address this issue, I turned to a different library called 'mui/pickers' but still struggled to achieve the desired fo ...