fix click comment once more then esc not work

This commit is contained in:
hjlarry 2025-09-15 11:11:07 +08:00
parent 72cdbdba0f
commit 9fda130b3a
1 changed files with 16 additions and 1 deletions

View File

@ -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<CommentInputProps> = memo(({ position, onSubmit, o
const textareaRef = useRef<HTMLTextAreaElement>(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()) {