Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/browser/components/CommandSuggestions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,18 @@ export const CommandSuggestions: React.FC<CommandSuggestionsProps> = ({
null
);
const menuRef = useRef<HTMLDivElement>(null);
const selectedRef = useRef<HTMLDivElement>(null);

// Reset selection whenever suggestions change
useEffect(() => {
setSelectedIndex(0);
}, [suggestions]);

// Scroll selected item into view
useEffect(() => {
selectedRef.current?.scrollIntoView({ block: "nearest" });
}, [selectedIndex]);

// Calculate position when using portal mode
useLayoutEffect(() => {
if (!anchorRef?.current || !isVisible) {
Expand Down Expand Up @@ -153,6 +159,7 @@ export const CommandSuggestions: React.FC<CommandSuggestionsProps> = ({
{suggestions.map((suggestion, index) => (
<div
key={suggestion.id}
ref={index === selectedIndex ? selectedRef : undefined}
onMouseEnter={() => setSelectedIndex(index)}
onClick={() => onSelectSuggestion(suggestion)}
id={`${resolvedListId}-option-${suggestion.id}`}
Expand Down
9 changes: 6 additions & 3 deletions src/browser/stories/App.chat.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ npm test 2>&1 | head -20`,
const toolHeader = canvas.getByText(/set -e/);
await userEvent.click(toolHeader);
});
// Remove unintended focus state for deterministic visual snapshot
// Wait for any auto-focus timers (ChatInput has 100ms delay), then blur
await new Promise((resolve) => setTimeout(resolve, 150));
(document.activeElement as HTMLElement)?.blur();
},
};
Expand Down Expand Up @@ -299,7 +300,8 @@ export const WithBashToolWaiting: AppStory = {
const toolHeader = canvas.getByText(/npm test/);
await userEvent.click(toolHeader);
});
// Remove unintended focus state for deterministic visual snapshot
// Wait for any auto-focus timers (ChatInput has 100ms delay), then blur
await new Promise((resolve) => setTimeout(resolve, 150));
(document.activeElement as HTMLElement)?.blur();
},
};
Expand Down Expand Up @@ -448,7 +450,8 @@ export const GenericTool: AppStory = {
const toolHeader = canvas.getByText("fetch_data");
await userEvent.click(toolHeader);
});
// Remove unintended focus state for deterministic visual snapshot
// Wait for any auto-focus timers (ChatInput has 100ms delay), then blur
await new Promise((resolve) => setTimeout(resolve, 150));
(document.activeElement as HTMLElement)?.blur();
},
};
Expand Down