import { memo, useId } from "react"; import { OptionLike } from "../select-legacy"; import { useListItem } from "@floating-ui/react"; import { useAutocomplete } from "./useAutocompleteContext"; import clsx from "clsx"; import { getOptionLabel, getOptionValue } from "./util"; export type AutocompleteOptionProps = O; export const AutocompleteOption = memo(function AutocompleteOption( props: AutocompleteOptionProps, ) { const label = getOptionLabel(props); const id = useId(); const { activeIndex, selection, getItemProps, handleSelect } = useAutocomplete(); const { ref, index } = useListItem({ label }); const isActive = activeIndex === index; const isSelected = selection ? getOptionValue(selection) === getOptionValue(props) : false; return (
handleSelect(index), })} > {label}
); });