Opening a Material UI dialog results in a change in the style of other components

Whenever I open the Dialog component from a button on the AppBar component, the margin on my navbar elements changes unexpectedly. I have checked the HTML using dev tools and there are no CSS changes on either of the components. Any suggestions on how to properly debug this issue or where to look in the MUI docs would be helpful.

Update: The class .MuiTouchRipple-root is attached to my AddCircle component.

import React from 'react';
import Navbar from './components/Navbar';
import Home from './pages/Home';
import Box from '@mui/material/Box';
import {
  BrowserRouter as Router,
  Switch,
  Route
} from "react-router-dom";
import { useState } from 'react';
import SelectInvoiceDialog from './components/SelectInvoiceDialog';
import ProcessInvoice from './pages/ProcessInvoice';

function App() {
  const [open, setOpen] = useState(false);
  const openSelectDialog = () => setOpen(true);
  const closeSelectDialog = () => setOpen(false);

  return (
    <Router>
      <Box>
        <Navbar openDialog={openSelectDialog}/>
        <Switch>
          <Route exact path="/process">
            <ProcessInvoice />
          </Route>
          <Route exact path="/">
            <Home />
          </Route>
        </Switch>
      </Box>
      <SelectInvoiceDialog open={open} closeAction={closeSelectDialog}/>
    </Router>
  );
}

export default App;

import React from "react";
import AppBar from '@mui/material/AppBar';
import Box from '@mui/material/Box';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
import AddCircle from '@material-ui/icons/AddCircle'
import IconButton from '@mui/material/IconButton';
import MenuIcon from '@material-ui/icons/Menu';
import { makeStyles, createStyles } from "@material-ui/core";

const useStyles = makeStyles((theme) => createStyles({
    navBarStyle: {
        background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
        display: 'flex',
        flexDirection: 'row',
        color: 'white'
    }
}));

export default function Navbar ({ openDialog }) {
    const classes = useStyles();
    return (
      <Box>
        <AppBar position="static">
          <Toolbar className={classes.navBarStyle}>
            <IconButton
              size="large"
              edge="start"
              color="inherit"
              aria-label="menu"
            >
              <MenuIcon />
            </IconButton>
            <Typography variant="h6" component="div" sx={{ flexGrow: 1 }}>Invoice processor</Typography>
            <IconButton
              size="large"
              color="inherit"
              onClick={openDialog}
            >
              <AddCircle />
            </IconButton>
          </Toolbar>
        </AppBar>
      </Box>
    );
}
import Button from '@material-ui/core/Button';
import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
import { DialogTitle, Select, MenuItem, FormControl, InputLabel, Box, TextField, Typography} from "@mui/material";
import { Link } from 'react-router-dom';
import { useState } from 'react';

export default function SelectInvoiceDialog ({ open, closeAction }) {
    const [filePath, setFilePath] = useState('');
    const [selection, setSelection] = useState('');

    const handleChange = (e) => setSelection(e.target.value);

    return (
      <Dialog 
        open={open} 
        onClose={closeAction}
        fullWidth
        disableEnforceFocus
      >
        <DialogTitle>Process Invoice</DialogTitle>
        <DialogContent>
          <FormControl fullWidth>
            <InputLabel id="selectTemplateLabel">Template</InputLabel>
            <Select
              labelId="selectTemplateLabel"
              id="selectTemplate"
              value={selection}
              onChange={handleChange}
              label="Template"
            >
              <MenuItem value={'DELL'}>DELL</MenuItem>
              <MenuItem value={'AI'}>Automatic AI</MenuItem>
              <MenuItem value={'30'}>Thirty</MenuItem>
            </Select>
          </FormControl>
          <FormControl fullWidth>
            <TextField label="Debtor Number"/>
          </FormControl>
          <FormControl>
            <Typography>{filePath ? 'File name:' : ''} {filePath}</Typography>
            <Button
              variant="contained"
              component="label"
              size="large"
            >
              SELECT FILE
              <input type="file" hidden onChange={(e) => setFilePath(e.target.files[0].name)}/>
            </Button>
          </FormControl>
          <DialogActions>
            <Button 
              variant="contained" 
              onClick={() => {
                closeAction();
                setFilePath('');
              }}
              component={Link} 
              to='/process'
            >Process</Button>
          </DialogActions>
        </DialogContent>
      </Dialog>
    );
}

Answer №1

It's highly likely that the issue stems from combining @mui and @material-ui in your code.

Answer №2

According to what Jeffrey Pinyan mentioned, it's important to avoid mixing imports to prevent any styling issues.

Importing '@material-ui/core/....' refers to an older version of MUI, while '@mui/material/....' refers to the newer version. Make sure to stick to one consistent method of importing to maintain consistency and prevent conflicts.

Keep your MUI imports in the same place to ensure everything works smoothly.

Answer №3

The solution was to include additional CSS in the body of the HTML.

body {
  margin: 0;
  padding: 0;
}

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

What could be the reason for the unexpected occurrence of my CSS rule application?

In my collection of CSS files, I have a specific class defined in the common CSS file: common.css .container-example { display: grid; height: 100%; width: 100%; background-color: black; } .container-example > div { overflow: hidden; } This ...

Create a data attribute object and assign to it the prop object received from the parent component

I am struggling with passing an object as a prop from a parent component and then utilizing it to initialize the child component with the received value. The main objective behind this is to create a dialog box that includes a child form component with mu ...

What is the best way to assign an ID to a specific HTML element within NetSuite's Document Object Model

Attempting to utilize jQuery in NetSuite to assign a value to an element for testing purposes, but struggling to locate the HTML DOM ID of certain custom drop-down lists. It's not the internal ID. For example: <input type="text" id="soid"> Wh ...

Sending Unique Identifier to AJAX Script

As I delve into my inaugural AJAX script, coupled with PHP pages, the intricacies of AJAX are slowly revealing themselves to me. Being relatively new to Javascript, I have managed to successfully implement the script. The task at hand involves enhancing a ...

`Wrong class names within Material UI when using styled components in a react environment`

Utilizing react-frame-component to load a unique custom component designed with both material ui and styled-components. The specific details of the custom component are not crucial, but here is some pertinent code snippet: const StyledCardHeader = styled( ...

What is the method for substituting one text with another using two-way data binding?

I implemented two different cases in my Mat-Table. When there is no data, the user will see a message saying "No Data Found". However, if the user enters text in the filter search, the "No Data Found" message should be hidden and replaced with the entered ...

What is the best way to leverage an existing user database and integrate user authentication into a fresh project?

I have recently taken on the task of revamping an established project by creating a brand new frontend from scratch. After careful consideration, I have opted to develop a straightforward Vue/Node.JS project. Within the current framework lies a Postgres d ...

Issue: Unhandled TypeError: Problem detected when calling storage.set(object items, optional function callback) in a Chrome Extension

Attempting to create my first Chrome extension, focusing on blocking access to specific websites like Facebook or Instagram. Using code to close tabs if the blocked sites are accessed. In a separate HTML file, providing users with two radio button options ...

Showing a 2D array in Jquery within an MVC environment - what's the solution?

I am in the process of building an MVC application. My goal is to transmit data from the controller and display it using JQuery. I have constructed an array in the controller and sent it to JQuery using Json. Here is the array... And here is the JQuery ...

The ashx file is triggered with every server control postback in jqgrid

I have an asp .net webforms page with a jqgrid, as well as several other server controls. The jqgrid is populated using an ashx file which retrieves data from the database and binds it successfully. Challenge Whenever a postback occurs (such as from a dro ...

The navigation bar is not extending to fill the entire width of the screen

I recently created a navigation bar using the nav tag and applied CSS to set the width, border, and padding. However, I noticed that there are some empty pixels on each side of the navigation bar that I can't seem to fill up. Here is the HTML code for ...

JS: Decreasing the counter while calling the hide() function

If I have a standard count <?php echo "Today (".mysql_num_rows($query)."); ?> It will display as Today (10) if there are 10 entries. Beneath this counter is a while() loop that displays all the rows in a <tr>. Within each <td> in the ...

If a number already exists, create 3 tables using MySQL and PHP

Currently facing an issue, I am in the process of developing a custom registration form for a browser game. I need to assign planets upon registration to users. Here's the breakdown: 9 galaxies, each galaxy consisting of 400 systems with each syste ...

Obscured painting surface appearance using Three.js

I am attempting to incorporate a blurred texture into my Three.js scene, but the results are not what I expected. Canvas: var c = document.getElementById("myCanvas"); var context1 = c.getContext("2d"); context1.filter = "blur(16px)"; context1.beginPath( ...

What is the best way to extract data from the JSON response obtained from the Facebook Graph API in a Node

I am struggling to parse a JSON file in order to extract specific data, particularly the latest picture. How can I achieve this using Node.js and the Facebook Graph API? Below is the snippet of code I currently have: var params = { hostname: ' ...

A guide to sharing session variables with express views

Struggling to access session variables in EJS views and encountering various challenges. To locally access req.session, I've implemented middleware as outlined in this guide on accessing Express.js req or session from Jade template. var express = re ...

Creating a secure ZIP file with password protection using node.js

Currently, I am faced with the challenge of creating a ZIP file in node.js with password protection. Despite using the "node-zip" module for this task, it lacks the functionality to provide password protection: var zip = new require('node-zip') ...

Displaying JSON data in HTML using Angular

If you have a straightforward controller: controller: function($scope, $http){ $http.get(templateSource+'/object.customer') .then(function(result){ $scope = result.data; }); } The content of my object.customer file is a ...

"Troubleshooting: Why is Angular's Equalizer from Foundation not

I'm having trouble getting Foundation Equalizer (the JS tool for equalizing div heights) to function properly. The demo is not displaying correctly. I am currently using Foundation v6.1.2 My setup includes using it in an ng-view, and in the index fi ...

When the textfield mui is set to shrink, an additional space appears in the label when using a font size of 12px

Struggling to customize the appearance of the textField component, particularly with the label when it is minimized: import * as React from "react"; import TextField from "@mui/material/TextField"; import { createTheme } from "@mui ...