简体   繁体   中英

Material UI Tooltip does not appear when rendered inside of a custom Modal component

Here is how my custom Modal component is defined:

function Modal({ open, set_open, children }) {
  const modal_ref = useRef(null);
  useEffect(() => {
    if (open) {
      modal_ref.current.style.display = "block";
    } else {
      modal_ref.current.style.display = "none";
    }
  }, [open]);

  return ReactDom.createPortal(
    <div className="modal-container" ref={modal_ref}>
      <div className="modal-content">{children}</div>
    </div>,
    document.getElementById("root")
  );
}

The children property of the component will contain the tooltip. Or it may actually be the grandchildren.

But either way, it should appear, no?

.MuiTooltip-popper {
    z-index: 9999999 !important;
}

As much as I hate using !important , that's what did the trick for me.

You can set this via a mui theme override as well.

export default function ThemeProvider({ children }: Props) {
  const theme = createTheme({
    zIndex: { tooltip: 99999 },
  });

  return (
    <MUIThemeProvider theme={theme}>
      {children}
    </MUIThemeProvider>
  );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM