Reduce font autocomplete scroll effect

This commit is contained in:
Neil
2026-05-31 03:34:19 -07:00
parent 49153d933f
commit a040f72652
@@ -456,7 +456,6 @@ export function FontAutocomplete({
const inputRef = useRef<HTMLInputElement | null>(null)
const rootRef = useRef<HTMLDivElement | null>(null)
const previewFontFamilyRef = useRef(onPreviewFontFamily)
const optionRefs = useRef(new Map<string, HTMLButtonElement>())
const listboxId = useId()
previewFontFamilyRef.current = onPreviewFontFamily
@@ -523,19 +522,6 @@ export function FontAutocomplete({
}
}
useEffect(() => {
if (!open || highlightedIndex < 0) {
return
}
const highlightedFont = filteredSuggestions[highlightedIndex]
if (!highlightedFont) {
return
}
optionRefs.current.get(highlightedFont)?.scrollIntoView({ block: 'nearest' })
}, [filteredSuggestions, highlightedIndex, open])
// Why: notify the consumer of the currently-highlighted font so it can
// render a live preview. Closing the dropdown or moving past all options
// clears the preview back to the committed value.
@@ -672,11 +658,9 @@ export function FontAutocomplete({
role="option"
aria-selected={index === highlightedIndex}
ref={(element) => {
if (element) {
optionRefs.current.set(font, element)
return
if (element && index === highlightedIndex) {
element.scrollIntoView({ block: 'nearest' })
}
optionRefs.current.delete(font)
}}
onMouseDown={(e) => e.preventDefault()}
onMouseEnter={() => setHighlightedIndex(index)}