材料UI工具提示在触发对话框关闭后保持打开状态

问题描述 投票:14回答:2

我的假设是Dialog的状态导致问题,但我无法弄清楚这一点。工具提示按预期工作,直到单击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>
    );
  }
}
reactjs material-design material-ui
2个回答
10
投票

请参阅问题#9624

这是预期的行为。它是为了可访问性考虑而完成的。您有两个选项,要么禁用工具提示响应以聚焦事件,要么禁用对话框还原焦点行为。

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


6
投票

根据此doc https://material-ui.com/api/tooltip/设置disableFocusListener = {true}

© www.soinside.com 2019 - 2024. All rights reserved.