import { useEffect, useRef } from "react"; import classNames from "classnames/dedupe"; import { getOptionValue, getOptionLabel, buildOptionTestId } from "./utils"; import type { ComboboxOption, ComboboxOptionProps } from "./types"; export const Option = ({ option, isHighlighted, onOptionSelect, optionComponent: OptionComponent, optionTestIdPrefix, id, }: ComboboxOptionProps) => { const optionRef = useRef(null); const optionValue = getOptionValue(option) || ""; const testId = buildOptionTestId( optionTestIdPrefix || "combobox-option", optionValue, ); useEffect(() => { if ( isHighlighted && optionRef.current && optionRef.current.scrollIntoView ) { optionRef.current.scrollIntoView({ block: "nearest" }); } }, [isHighlighted]); return (
  • onOptionSelect(option)} className={classNames("mobius-combobox__option", "has-pii", { "mobius-combobox__option--is-highlighted": isHighlighted, })} > {OptionComponent ? ( ) : ( getOptionLabel(option) )}
  • ); };