Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
917 views
in Technique[技术] by (71.8m points)

Material UI zIndex in classes ignored, working in inline style. Why?

I am trying to use Material UI Popper in another Popper and I had an zIndex issue.
I fixed it but I don't fully understand what is happening: Material UI zIndex in classes is ignored while zIndex in inline style is working.
I can't get why. Could you help me or give me a pointer?

Here is the code I am running:

import { useState } from "react";
import { makeStyles } from "@material-ui/core/styles";
import Popper from "@material-ui/core/Popper";
import ClickAwayListener from "@material-ui/core/ClickAwayListener";
import Paper from "@material-ui/core/Paper";
import AvatarEdit from "react-avatar-edit";

import PropTypes from "prop-types";

const useStyles = makeStyles((theme) => ({
  popper: {
    zIndex: 99, //Ignored
    backgroundColor: "red",
    width: "800px",

    '&[x-placement*="right"] $arrow': {
      left: 0,
      marginLeft: "-0.9em",
      height: "3em",
      width: "1em",
      "&::before": {
        borderWidth: "1em 1em 1em 0",
        borderColor: `transparent ${theme.palette.background.paper} transparent transparent`,
      },
    },
  },
}));

export default function ActivityEditor(props) {
  const [avatar, setAvatar] = useState();
  const [src, setSrc] = useState();
  const classes = useStyles();

  return (
    console.log("classes.popper =", classes.popper) || (
      <ClickAwayListener
        mouseEvent="onMouseDown"
        touchEvent="onTouchStart"
        onClickAway={props.onClose}
      >
        <Popper
          style={{ zIndex: 2 }}
          classes={classes.popper}
          aria-labelledby="simple-dialog-title"
          open={props.open}
          anchorEl={props.anchorEl}
          placement={"right-start"}
          modifiers={{
            flip: {
              enabled: true,
            },
            preventOverflow: {
              enabled: true,
              boundariesElement: "scrollParent",
            },
            offset: {
              enabled: true,
              offset: "0, -40px",
            },
          }}
        >
          <Paper elevation={3}>
            <div>
              <AvatarEdit
                width={390}
                height={295}
                onCrop={(avatar) => setAvatar(avatar)}
                onClose={() => setAvatar(null)}
                //onBeforeFileLoad={this.onBeforeFileLoad}
                src={src}
              />
              <img src={avatar} alt="Avatar Preview" />
            </div>
          </Paper>
        </Popper>
      </ClickAwayListener>
    )
  );
}

ActivityEditor.propTypes = {
  open: PropTypes.bool.isRequired,
  anchorEl: PropTypes.object.isRequired,
  onClose: PropTypes.func.isRequired,
};
question from:https://stackoverflow.com/questions/65641405/material-ui-zindex-in-classes-ignored-working-in-inline-style-why

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...