fix: @mention popover position calculation with requestAnimationFrame

main
sp mac bookpro 2605 2026-06-07 20:33:39 +08:00
parent d649d4364d
commit 2d4c57a78b
1 changed files with 13 additions and 6 deletions

View File

@ -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;
// 计算位置 - 使用 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;
}
}