![](/img/trans.png)
[英]React-google-recaptcha does not appear in the modal when the component is rendered
[英]Material UI Tooltip does not appear when rendered inside of a custom Modal component
以下是我的自定義模態組件的定義方式:
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")
);
}
組件的 children 屬性將包含工具提示。 或者它實際上可能是孫子。
但無論哪種方式,它都應該出現,不是嗎?
.MuiTooltip-popper {
z-index: 9999999 !important;
}
盡管我討厭使用!important
,但這對我有用。
您也可以通過 mui 主題覆蓋來設置它。
export default function ThemeProvider({ children }: Props) {
const theme = createTheme({
zIndex: { tooltip: 99999 },
});
return (
<MUIThemeProvider theme={theme}>
{children}
</MUIThemeProvider>
);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.