@devries-cameron20 / t3code Mirror · read-only / commits / 4a4795e5f0
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 25, 07:30 UTC

Scroll active item into view in composer menu (#1557)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Naufal Putra committed Mar 30, 2026 at 12:33 UTC 4a4795e5f0f0083e16de64b86b499d8cca718b52
1 file changed +17 -3
apps/web/src/components/chat/ComposerCommandMenu.tsx
+17 -3
@@ -1,5 +1,5 @@
1 import { type ProjectEntry, type ProviderKind } from "@t3tools/contracts";
2 -import { memo } from "react";
2 +import { memo, useLayoutEffect, useRef } from "react";
3 import { type ComposerSlashCommand, type ComposerTriggerKind } from "../../composer-logic";
4 import { BotIcon } from "lucide-react";
5 import { cn } from "~/lib/utils";
@@ -41,6 +41,16 @@ export const ComposerCommandMenu = memo(function ComposerCommandMenu(props: {
41 onHighlightedItemChange: (itemId: string | null) => void;
42 onSelect: (item: ComposerCommandItem) => void;
43 }) {
44 + const listRef = useRef<HTMLDivElement>(null);
45 +
46 + useLayoutEffect(() => {
47 + if (!props.activeItemId || !listRef.current) return;
48 + const el = listRef.current.querySelector<HTMLElement>(
49 + `[data-composer-item-id="${CSS.escape(props.activeItemId)}"]`,
50 + );
51 + el?.scrollIntoView({ block: "nearest" });
52 + }, [props.activeItemId]);
53 +
54 return (
55 <Command
56 autoHighlight={false}
@@ -51,7 +61,10 @@ export const ComposerCommandMenu = memo(function ComposerCommandMenu(props: {
61 );
62 }}
63 >
54 - <div className="relative overflow-hidden rounded-xl border border-border/80 bg-popover/96 shadow-lg/8 backdrop-blur-xs">
64 + <div
65 + ref={listRef}
66 + className="relative overflow-hidden rounded-xl border border-border/80 bg-popover/96 shadow-lg/8 backdrop-blur-xs"
67 + >
68 <CommandList className="max-h-64">
69 {props.items.map((item) => (
70 <ComposerCommandMenuItem
@@ -88,8 +101,9 @@ const ComposerCommandMenuItem = memo(function ComposerCommandMenuItem(props: {
101 return (
102 <CommandItem
103 value={props.item.id}
104 + data-composer-item-id={props.item.id}
105 className={cn(
92 - "cursor-pointer select-none gap-2 data-highlighted:bg-transparent data-highlighted:text-inherit",
106 + "cursor-pointer select-none gap-2 hover:bg-transparent hover:text-inherit data-highlighted:bg-transparent data-highlighted:text-inherit",
107 props.isActive && "bg-accent! text-accent-foreground!",
108 )}
109 onMouseMove={() => {