diff --git a/src/pages/chat/components/ChatInput.tsx b/src/pages/chat/components/ChatInput.tsx index 43b7f1e..7cfc5c8 100644 --- a/src/pages/chat/components/ChatInput.tsx +++ b/src/pages/chat/components/ChatInput.tsx @@ -74,12 +74,19 @@ export default function ChatInput(props: { console.log('[@mention] matched @ at position:', { atIndex, query }); if (!query.includes(' ')) { setMentionQuery(query); - // 计算位置 - const textarea = e.target; - const rect = textarea.getBoundingClientRect(); - setMentionPos({ top: rect.bottom, left: rect.left + 10 }); - console.log('[@mention] show popover:', { top: rect.bottom, left: rect.left + 10, query }); - setShowMentionPopover(true); + // 计算位置 - 使用 inputRef 获取最新 DOM 位置 + requestAnimationFrame(() => { + const textarea = inputRef.current; + if (!textarea) { + console.log('[@mention] inputRef.current is null'); + return; + } + const rect = textarea.getBoundingClientRect(); + console.log('[@mention] textarea rect:', rect); + setMentionPos({ top: rect.bottom, left: rect.left + 10 }); + console.log('[@mention] show popover:', { top: rect.bottom, left: rect.left + 10, query }); + setShowMentionPopover(true); + }); return; } }