reactjs - 触发对话框关闭后, Material UI 工具提示保持打开状态

标签 reactjs material-design material-ui

我的假设是对话框的状态导致了问题,但我无法弄清楚这一点。工具提示按预期工作,直到单击 IconButton。对话框按其应有的方式弹出,但是当退出对话框时,工具提示会弹出为事件状态。

class DeleteDocument extends React.Component {
  state = {
    open: false,
  };

  onDeleteFile() {
    try {
      ensureJobIsUnlocked();
    } catch (err) {
      return;
    }

    const confirmedByUser = true;
    if (confirmedByUser) {
      this.props.onDeleteFile(this.props.selectedDocument.id);
      this.setState({ open: false });
    }
  }

  handleClickOpen = () => {
    this.setState({ open: true });
  };

  handleClose = () => {
    this.setState({ open: false });
  };

  render() {
    return (
      <div>
        <Tooltip id="tooltip-icon" title="Delete Document">
          <div>
            <IconButton
              disabled={(this.props.selectedDocument == null)}
              onClick={this.handleClickOpen}
            >
              <DeleteIcon />
            </IconButton>
          </div>
        </Tooltip>
        <Dialog
          open={this.state.open}
          onClose={this.handleClose}
          aria-labelledby="alert-dialog-title"
          aria-describedby="alert-dialog-description"
        >
          <DialogTitle id="alert-dialog-title">{'Delete Document'}</DialogTitle>
          <DialogContent>
            <DialogContentText id="alert-dialog-description">
              This will delete the currently active PDF/Component Design. Are you sure you want to do this?
            </DialogContentText>
          </DialogContent>
          <DialogActions>
            <Button onClick={this.handleClose} color="primary">
              Cancel
            </Button>
            <Button onClick={this.onDeleteFile.bind(this)} color="primary" autoFocus>
              Delete
            </Button>
          </DialogActions>
        </Dialog>
      </div>
    );
  }
}

最佳答案

查看问题#9624 :

This is the expected behavior. It's done for accessibility considerations. You have two options, either disable the tooltip response to focus events or disable the dialog restore focus behavior.

<强>1。禁用对焦点事件的工具提示响应 ( docs )

<Tooltip disableTriggerFocus={true} />

Edit Material-ui - tooltip disable restore focus trigger

<强>2。禁用对话框恢复焦点行为 ( docs )

<Dialog disableRestoreFocus={true} />

Edit Material-ui - tooltip disable restore focus

关于reactjs - 触发对话框关闭后, Material UI 工具提示保持打开状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50122739/

相关文章:

reactjs - 如何将 className 样式传递给 `material-ui` 中的子组件?

JavaScript 切换 Material Design Lite 开关

angular - 如何更改 Angular Material 步进器步骤图标的颜色

reactjs - 捕获 Material UI 弃用警告

javascript - 在 Google map (React) 中获取可拖动标记位置 (lat,lng)

reactjs - useContext 到底做了什么?

javascript - 变量在定义之前被使用

Android Material 设计 - LinearLayout elevation

javascript - 如何为我的 React 应用程序解决 "Element type is invalid"?

reactjs - Material UI React Paper 组件在嵌套网格显示问题