Reduce font autocomplete scroll effect
This commit is contained in:
@@ -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)}
|
||||
|
||||
Reference in New Issue
Block a user