import { type CSSProperties, useLayoutEffect, useRef } from "react"; import { Avatar } from "../ui/Avatar.tsx"; import type { UserResult } from "../../hooks/useMentionAutocomplete.ts"; interface MentionDropdownProps { /** For the textarea's `aria-controls` / `aria-activedescendant`. */ id: string; results: UserResult[]; selectedIndex: number; onSelect: (username: string) => void; /** Fixed-position placement from `useAnchoredFloat`; see TextEditor. */ style?: CSSProperties; } export function MentionDropdown( { id, results, selectedIndex, onSelect, style }: MentionDropdownProps, ) { const listRef = useRef(null); // Arrowing past the visible rows keeps the selection in view. useLayoutEffect(() => { listRef.current ?.querySelector("[aria-selected='true']") ?.scrollIntoView({ block: "nearest" }); }, [selectedIndex, results]); if (results.length === 0) return null; return ( ); }