diff --git a/apps/web/src/components/chat/ComposerCommandMenu.tsx b/apps/web/src/components/chat/ComposerCommandMenu.tsx index cc48e9ae21..fc7ea27c29 100644 --- a/apps/web/src/components/chat/ComposerCommandMenu.tsx +++ b/apps/web/src/components/chat/ComposerCommandMenu.tsx @@ -1,5 +1,5 @@ import { type ProjectEntry, type ProviderKind } from "@t3tools/contracts"; -import { memo } from "react"; +import { memo, useLayoutEffect, useRef } from "react"; import { type ComposerSlashCommand, type ComposerTriggerKind } from "../../composer-logic"; import { BotIcon } from "lucide-react"; import { cn } from "~/lib/utils"; @@ -41,6 +41,16 @@ export const ComposerCommandMenu = memo(function ComposerCommandMenu(props: { onHighlightedItemChange: (itemId: string | null) => void; onSelect: (item: ComposerCommandItem) => void; }) { + const listRef = useRef(null); + + useLayoutEffect(() => { + if (!props.activeItemId || !listRef.current) return; + const el = listRef.current.querySelector( + `[data-composer-item-id="${CSS.escape(props.activeItemId)}"]`, + ); + el?.scrollIntoView({ block: "nearest" }); + }, [props.activeItemId]); + return ( -
+
{props.items.map((item) => ( {