From c91350a7411553af56c1c242e5caaba829029701 Mon Sep 17 00:00:00 2001 From: probieluo <17764593623@163.com> Date: Fri, 8 May 2026 15:51:25 +0800 Subject: [PATCH] fix: add Enter key support for warning dialog confirmation(#554) --- frontend/src/utils/discrete.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/frontend/src/utils/discrete.js b/frontend/src/utils/discrete.js index 122b8a6e..9ff5240e 100644 --- a/frontend/src/utils/discrete.js +++ b/frontend/src/utils/discrete.js @@ -75,18 +75,39 @@ function setupDialog(dialog) { return dialog.create(option) }, warning: (content, onConfirm) => { - return dialog.warning({ + const handleDialogEnter = (e) => { + if (e.key !== 'Enter') { + return + } + + e.preventDefault() + onConfirm && onConfirm() + dialogInstance?.destroy && dialogInstance.destroy() + cleanup() + } + + const cleanup = () => { + window.removeEventListener('keydown', handleDialogEnter) + } + + const dialogInstance = dialog.warning({ title: i18nGlobal.t('common.warning'), content: content, closable: false, - autoFocus: false, + autoFocus: true, transformOrigin: 'center', positiveText: i18nGlobal.t('common.confirm'), negativeText: i18nGlobal.t('common.cancel'), onPositiveClick: () => { onConfirm && onConfirm() + cleanup() + }, + onNegativeClick: () => { + cleanup() }, }) + window.addEventListener('keydown', handleDialogEnter) + return dialogInstance }, } }