From 7d997655899809f16ff2a7e352047c5f11b2eb3b Mon Sep 17 00:00:00 2001 From: FischLu Date: Wed, 19 Feb 2025 14:29:17 +0100 Subject: [PATCH] fix: fix the issue where the menu scrolls back to the top after clicking an option --- .../src/pages/home/Inputbar/MentionModelsButton.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/renderer/src/pages/home/Inputbar/MentionModelsButton.tsx b/src/renderer/src/pages/home/Inputbar/MentionModelsButton.tsx index 5ebf7fac..36ce439f 100644 --- a/src/renderer/src/pages/home/Inputbar/MentionModelsButton.tsx +++ b/src/renderer/src/pages/home/Inputbar/MentionModelsButton.tsx @@ -174,12 +174,13 @@ const MentionModelsButton: FC = ({ mentionModels, onMentionModel: onSelec loadPinnedModels() }, []) - // Scroll to the first menu item when the mode selection menu opens useLayoutEffect(() => { - if (isOpen && flatModelItems.length > 0 && itemRefs.current[0]) { - itemRefs.current[0].scrollIntoView({ block: 'nearest' }) + if (isOpen && selectedIndex > -1 && itemRefs.current[selectedIndex]) { + requestAnimationFrame(() => { + itemRefs.current[selectedIndex]?.scrollIntoView({ block: 'nearest' }) + }) } - }, [isOpen, flatModelItems]) + }, [isOpen, selectedIndex]) useEffect(() => { const showModelSelector = () => {