最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Material UI Tooltip does not appear when rendered inside of a custom Modal component - Stack Overflow

programmeradmin2浏览0评论

Here is how my custom Modal ponent 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 ponent will contain the tooltip. Or it may actually be the grandchildren.

But either way, it should appear, no?

Here is how my custom Modal ponent 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 ponent will contain the tooltip. Or it may actually be the grandchildren.

But either way, it should appear, no?

Share Improve this question asked Jul 31, 2021 at 14:05 Bear Bile Farming is TortureBear Bile Farming is Torture 5,1618 gold badges41 silver badges118 bronze badges 3
  • It can be a z-index problem. please increase the z-index of the tooltip larger than the modal – TopW3 Commented Jul 31, 2021 at 14:37
  • I tried that. I applied the highest zIndex to the style property of the Tooltip. Didn't work – Bear Bile Farming is Torture Commented Jul 31, 2021 at 19:41
  • Please provide a code sandbox reproducing your problem. – Ryan Cogswell Commented Aug 1, 2021 at 3:40
Add a ment  | 

2 Answers 2

Reset to default 7
.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>
  );
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论