在自定义模态组件内部渲染时,材质 UI 工具提示不会出现

una*_*der 3 javascript modal-dialog popup reactjs material-ui

以下是我的自定义模态组件的定义方式:

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

组件的 Children 属性将包含工具提示。或者实际上可能是孙子。

但无论如何,它都应该出现,不是吗?

Jam*_*mes 5

.MuiTooltip-popper {
    z-index: 9999999 !important;
}
Run Code Online (Sandbox Code Playgroud)

尽管我讨厌使用!important,但这就是对我有用的东西。