Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove border from MUI Modal

I am trying to use the React MUI Modal but I always get a black border around the modal when it is focused on. I have removed the border when it is out of focus, but if the modal is focused, the border comes back. Any suggestions on how to remove it?

https://codesandbox.io/s/material-demo-kk0ux?file=/demo.js

const useStyles = makeStyles(theme => ({
  paper: {
    position: "absolute",
    width: 400,
    backgroundColor: theme.palette.background.paper,
    boxShadow: theme.shadows[5],
    padding: theme.spacing(2, 4, 3)
  },
  modal: {
    "&:focus": {
      outline: "none"
    }
  }
}));

export default function SimpleModal() {
  const classes = useStyles();
  // getModalStyle is not a pure function, we roll the style only on the first render
  const [modalStyle] = React.useState(getModalStyle);
  const [open, setOpen] = React.useState(false);

  const handleOpen = () => {
    setOpen(true);
  };

  const handleClose = () => {
    setOpen(false);
  };

  const body = (
    <div style={modalStyle} className={classes.paper}>
      <h2 id="simple-modal-title">Text in a modal</h2>
      <p id="simple-modal-description">
        Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
      </p>
      <SimpleModal />
    </div>
  );

  return (
    <div>
      <button type="button" onClick={handleOpen}>
        Open Modal
      </button>
      <Modal
        className={classes.modal}
        open={open}
        onClose={handleClose}
        aria-labelledby="simple-modal-title"
        aria-describedby="simple-modal-description"
      >
        {body}
      </Modal>
    </div>
  );
}
like image 476
Sri Avatar asked Jun 10 '20 16:06

Sri


2 Answers

Set the outline: 'none' to your paper instead. That will fix your problem.

Also, i think that you should be using <Dialog> instead, as recommended in docs. You will keep your behavior without that focus.

like image 158
Diego Segura Avatar answered Nov 16 '22 16:11

Diego Segura


Wrap the body of the Modal tag in a and provide outline: none as a style

<div style={{outline:'none'}}>     
    {body}    
    </div>
like image 20
Atul Rai Avatar answered Nov 16 '22 17:11

Atul Rai