我有一个对话框和一个 ListItem,当你点击它时,它会通过显示一个弹出框进入编辑模式。这是在使用 Modal 的旧版 MUI 中工作的,但自从获得最新版本后不起作用,我正在尝试使用 Popover。我试图在 CodeSandox 上做一个简单的例子,但有效。发生的情况是 Popover 总是在页面的左上角而不是 ListItem。
我已经将我的代码简化为对话框中的一个简单的 Button 和 Popover,但仍然存在同样的问题,并且对接下来要尝试的内容没有想法。我在控制台中得到的错误是
[Warning] Material-UI: the `anchorEl` prop provided to the component is invalid.
The anchor element should be part of the document layout.
Make sure the element is present in the document or that it's not display none.
单击该项目时,我会像示例中那样执行 event.currentTarget,这就是 console.log 的样子。
[Log] <button class="MuiButtonBase-root MuiButton-root MuiButton-text" tabindex="0" type="button"> (main.chunk.js, line 26437)
<span class="MuiButton-label">Click Me</span>
<span class="MuiTouchRipple-root">
<span class="MuiTouchRipple-ripple MuiTouchRipple-rippleVisible" style="width: 117.2006825918689px; height: 117.2006825918689px; top: -34.60034129593445px; left: -25.60034129593445px;">
<span class="MuiTouchRipple-child MuiTouchRipple-childLeaving"></span>
</span>
</span>
</button>
我什至尝试在没有修复它的对话框中执行 disablePortal。我还尝试使用 refs 修复了 anchorEl 警告,但仍然相对于页面而不是元素显示。有任何想法吗?