From 9fda130b3a3f3d0681f010a86196513029415156 Mon Sep 17 00:00:00 2001 From: hjlarry Date: Mon, 15 Sep 2025 11:11:07 +0800 Subject: [PATCH] fix click comment once more then esc not work --- web/app/components/workflow/comment/input.tsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/web/app/components/workflow/comment/input.tsx b/web/app/components/workflow/comment/input.tsx index 9487089c1d..956cb884b0 100644 --- a/web/app/components/workflow/comment/input.tsx +++ b/web/app/components/workflow/comment/input.tsx @@ -1,5 +1,5 @@ import type { FC } from 'react' -import { memo, useCallback, useRef, useState } from 'react' +import { memo, useCallback, useEffect, useRef, useState } from 'react' import Textarea from 'react-textarea-autosize' import { RiSendPlane2Fill } from '@remixicon/react' import cn from '@/utils/classnames' @@ -18,6 +18,21 @@ export const CommentInput: FC = memo(({ position, onSubmit, o const textareaRef = useRef(null) const { userProfile } = useAppContext() + useEffect(() => { + const handleGlobalKeyDown = (e: KeyboardEvent) => { + if (e.key === 'Escape') { + e.preventDefault() + e.stopPropagation() + onCancel() + } + } + + document.addEventListener('keydown', handleGlobalKeyDown, true) + return () => { + document.removeEventListener('keydown', handleGlobalKeyDown, true) + } + }, [onCancel]) + const handleSubmit = useCallback(() => { try { if (content.trim()) {