从 React Material Modal 中移除边框

Sri*_*Sri 3 simplemodal reactjs material-ui

我正在尝试使用 React Material Modal,但是当它被聚焦时,我总是在模态周围出现黑色边框。我在离焦时移除了边框,但是如果模式聚焦,边框又回来了。有关如何删除它的任何建议?

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>
  );
}
Run Code Online (Sandbox Code Playgroud)

Die*_*ura 15

将 设置outline: 'none'为您的纸张。那将解决您的问题。

另外,我认为您应该按照docs 中的<Dialog>建议使用。没有那个焦点,你会保持你的行为。


小智 6

将 Modal 标签的主体包裹在 a 中并提供 border: none 作为样式

<div style={{outline:'none'}}>     
    {body}    
    </div>
Run Code Online (Sandbox Code Playgroud)