如何在单击确认反应谱 ModalTrigger 时关闭对话框?

发布于 2025-01-14 18:50:07 字数 733 浏览 2 评论 0原文

我有一个对话框,我正在使用来自反应谱(旧版本)的 ModalTrigger。该对话框有两个按钮,“确定”和“取消”。取消时无需执行任何操作,但应在单击“确定”时触发操作,对话框应关闭并启动操作。我能够启动操作,但对话框未关闭。

代码:

 <ModalTrigger>
            <Button label="Do something" variant="action"></Button>
            <Dialog
                    confirmLabel="Confirm"
                    cancelLabel="Cancel"
                    mode="confirmation"
                    onConfirm={props.confirmAction}
                    keyboardConfirm="true"
                    backdropClickable={true}>
                {title}

            </Dialog>
        </ModalTrigger>

当用户单击 onConfirm 然后启动 props.confirmAction 时,如何关闭对话框按钮?到目前为止,对话框在 props.confirmAction 完成之前不会关闭。

I have a dialog box which I am using from ModalTrigger from react spectrum(old version). The dialog box has two buttons, Okay and Cancel.Nothing to do on cancel, but the action should be triggered on clicking of Okay, the dialog box should close and action should initiate. I am able to initiate action but dialog box is not closing.

Code:

 <ModalTrigger>
            <Button label="Do something" variant="action"></Button>
            <Dialog
                    confirmLabel="Confirm"
                    cancelLabel="Cancel"
                    mode="confirmation"
                    onConfirm={props.confirmAction}
                    keyboardConfirm="true"
                    backdropClickable={true}>
                {title}

            </Dialog>
        </ModalTrigger>

How can I close the dialog button when user clicks onConfirm and then start props.confirmAction?As of now, the dialog box don't close until props.confirmAction completes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如痴如狂 2025-01-21 18:50:07

我们可以通过两种方式实现它。

  1. 编写一个方法并触发 dialog.dismiss ,然后触发 props。 verifyAction
const onClickConfirm ()=>{
  dialog.dismiss()
  props. confirmAction()
}
  1. 使用 onDismiss 而不是 onConfirm

We can achieve it in 2 ways.

  1. Write a method and trigger dialog.dismiss followed by props. confirmAction
const onClickConfirm ()=>{
  dialog.dismiss()
  props. confirmAction()
}
  1. Use onDismiss instead of onConfirm
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文