Issues with CSS arising from conflicts in MUI alert component styling

My experience with Material UI 5.10.11 has been mostly positive, but I have encountered some issues with the MuiAlert component. When setting severity to 'error', it should look like this https://i.sstatic.net/A1KIE.png

However, on certain pages, it appears differently https://i.sstatic.net/6PPOx.png

I've included my code below for reference. If anyone could take a look and help me identify what might be causing the problem, I would greatly appreciate it.

import React, { useState, useEffect } from 'react';
import { Snackbar } from '@mui/material';
import MuiAlert from '@mui/material/Alert';

const Alert = React.forwardRef(function Alert(props, ref) {
  return <MuiAlert elevation={24} ref={ref} variant="filled" {...props} />;
});

export default function MessageDialog(props) {
  const defaultPosition = {
    vertical: 'top',
    horizontal: 'center'
  };

  const autoHideDuration = 5000;

  const [open, setOpen] = useState(false);

  useEffect(() => {
    let timeoutId;

    if (props.open) {
      setOpen(true);
      timeoutId = setTimeout(() => {
        setOpen(false);
      }, autoHideDuration);
    }

    return () => {
      clearTimeout(timeoutId);
    };
  }, [props.open]);

  return (
    <>
      <Snackbar
        anchorOrigin={{
          vertical: defaultPosition.vertical,
          horizontal: defaultPosition.horizontal
        }}
        open={open}
      >
        <Alert severity={props.type} sx={{ width: '100%' }}>
          {props.children}
        </Alert>
      </Snackbar>
    </>
  );
}

Your assistance is greatly appreciated!

The issue seems to be related to the css as shown in the screenshots.

Answer №1

It appears that the issue is stemming from the Mui component class name being used as MuiPaper-root. This conflict arises when on a page with a white background, possibly due to other Mui components sharing the same class name. It may also be caused by a css file assigning a white background to the MuiPaper-root class specifically for that page.

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

Exciting Update: Next.js V13 revalidate not triggering post router.push

Currently using Next.js version 13 for app routing, I've encountered an issue with the revalidate feature not triggering after a router.push call. Within my project, users have the ability to create blog posts on the /blog/create page. Once a post is ...

The issue of "Container not being defined" in React is causing trouble

Trying to grasp the concepts of React, but encountering an error with 'Container' being undefined. Despite following all steps in the course, I can't seem to figure out the root cause of this issue. Below is a snippet from App.js: import Re ...

Ways to modify the color of a particular list item

I am looking to change the color of only the items in a list that contain a number to blue. Specifically, I want to target the first list (the ol li) that starts with a number in it. ol li { color: blue; } <ol> <li>League 1<br> ...

Error with firebase SSR: instead of accessing the website, a pop-up requesting permission to access your Google account appears

I've been working on a React SSR website using create-react basics with the help of the "razzle" helper tool. Initially, everything was functioning properly with the following code: 'use strict' const functions = require('firebase-funct ...

Tips for applying unique CSS classes to individual templates in Joomla

I manage a website at www.kadamjay.kg using an RT template system where each language version has its own unique template. However, when I add a class to a specific element, it only changes on one template and there are no additional templates in the pat ...

Android browser experiences a sudden surge of unexpected data influx

I am facing an issue with my application where it maps an array from the state. The array should ideally only contain 6 sets of data, as limited by the backend. However, sometimes it spikes and displays data that is not supposed to be there or shows old da ...

How to adjust the size of <img> in a Bootstrap carousel to fit the parent element using CSS

My webpage has a dynamic carousel feature where users can upload images, but I have no control over their dimensions. Despite some guidelines in place, it is uncertain if they will be followed. In my development tests, I have used three sample images: one ...

Utilizing CSS for positioning forms and images with floats

I have implemented a dropdown box that allows users to select one of eight images, which is then displayed on the webpage. However, currently the image appears directly above the dropdown box and I would like to format it so that the image is shown on the ...

Using the react-router Navigate component within a Next.js application allows for seamless

Is there a way to achieve the same result as the Navigate component in react-router within Nextjs? The next/Router option is available, but I am looking for a way to navigate by returning a component instead. I need to redirect the page without using rout ...

Encountering a problem with the state error while trying to modify an input field during onChange event

Whenever I pass state down from a parent component, the setState function keeps triggering an error that says setEmail is not a valid function on change event. Is there a simple solution to fix this issue? Every time I type a string into the email input f ...

Navigate to designated part of a website using HTML and CSS styling

Consider the following JavaScript code: //Scroll Down button $(window).scroll(function () { if ($(this).scrollDown() > 100) { $('.containerScroll').fadeIn('slow'); } else { $('.containerScroll').fadeOut('slow'); } ...

What is the best way to increase the size of the input field to allow for more typing space?

My query is quite simple. Even when I set the height to 100px, the cursor still starts in the middle of the input box. I want the entire box to be utilized with the cursor starting at the top left corner for a more intuitive paragraph writing experience. ...

I am interested in removing the X-axis labels from APEXCHARTS in a NextJs project

Is there a way to remove the X axis labels APEXCHARTS in NextJs? Here's an example image for reference I want to get rid of the number labels ranging from 2100 to 8000. I've already attempted using dataLabels, but it did not yield the desired out ...

Issue with the height of Bootstrap 4 navigation bar

After deciding to use Bootstrap 4 for my current project, I encountered an issue with the navbar. It seems to expand too much, which is only happening once I deploy the website. Can anyone help me figure out what's causing this problem? Below is the c ...

An error notification keeps appearing whenever the user enters text into the input field, using Redux with useSelector

Implementing login functionality with redux and saga using a functional component, I encountered an issue. When entering the wrong password or email, the error message persistently pops up when typing new information without even clicking the login button. ...

Obtain a third-party React component from a content delivery network (CDN) (such

My Django project incorporates React, with custom components already in place. However, I am struggling to import third-party components from a CDN. To attempt this, I first imported React (either the development or production version) in the base templat ...

flexboxgrid with a full viewport width and height, displaying scrollbars regardless

Hi there, I am encountering an issue where setting the width and height of the viewport causes scrollbars to appear when text is added inside <h1></h1>. This behavior is puzzling me as I have not experienced it before in my previous HTML and CS ...

Loading pages ahead of time in Next.js can help improve the user

Quick Summary: How can I preload pages before users navigate to them? I have a website that utilizes react-query for fetching and storing data. When a user first enters the site, they are shown a list of products which are stored in the cache. If a user c ...

Javascript Function : Toggle visibility of div when user clicks anywhere on the page

I have implemented a feature where clicking on the 3 dots reveals a div, and clicking again hides it. However, I would like the div to hide when clicking anywhere else on the document. Imagine two circles - clicking on one circle displays a div, while cli ...

React Header Component Experiencing Initial Scroll Jitters

Issue with Header Component in React Next.js Application Encountering a peculiar problem with the header component on my React-based next.js web application. When the page first loads and I begin scrolling, there is a noticeable jittery behavior before th ...