fix: fix the issue where the menu scrolls back to the top after clicking an option

This commit is contained in:
FischLu 2025-02-19 14:29:17 +01:00 committed by 亢奋猫
parent 5f6cf1bd66
commit 7d99765589

View File

@ -174,12 +174,13 @@ const MentionModelsButton: FC<Props> = ({ mentionModels, onMentionModel: onSelec
loadPinnedModels() loadPinnedModels()
}, []) }, [])
// Scroll to the first menu item when the mode selection menu opens
useLayoutEffect(() => { useLayoutEffect(() => {
if (isOpen && flatModelItems.length > 0 && itemRefs.current[0]) { if (isOpen && selectedIndex > -1 && itemRefs.current[selectedIndex]) {
itemRefs.current[0].scrollIntoView({ block: 'nearest' }) requestAnimationFrame(() => {
itemRefs.current[selectedIndex]?.scrollIntoView({ block: 'nearest' })
})
} }
}, [isOpen, flatModelItems]) }, [isOpen, selectedIndex])
useEffect(() => { useEffect(() => {
const showModelSelector = () => { const showModelSelector = () => {