我已经研究了许多有关弹出窗口锚定的问题,但在使用材料表库中的 MaterialTable 元素时我没有看到任何问题: https: //github.com/mbrn/material-table。
在调试时,anchorEl 看起来正确地保存了按钮引用,但它似乎第二次重新渲染并丢失了引用。据我所知,这是由于按钮被重新安装所致。所以最终的渲染默认将弹出框放在屏幕的左上角。我想知道是否有人找到了阻止这种重新安装或其他解决方法的方法。
export class UsersList extends Component {
constructor(props) {
super(props);
this.state = {
anchorEl: null,
anchorReference: "anchorEl"
};
}
render() {
const { classes } = this.props;
var { anchorEl } = this.state;
const open = Boolean(anchorEl);
return (
<MaterialTable
isLoading={this.state.isLoading}
columns={[
{ title: "Username", field: "username" },
...more columns
]}
data={this.state.users}
onRowClick={(evt, selectedRow) => this.setState({ selectedRow })}
//where I update my anchorEl on a click on the "edit" icon
actions={[
{
icon: …Run Code Online (Sandbox Code Playgroud)