import classnames from 'classnames'; import { ComboboxLabelSelection } from './ComboboxLabelSelection'; import { ComboboxInput } from './ComboboxInput'; import type { ComboboxSelectionProps } from '../ComboboxType'; import type { ChangeEvent } from 'react'; /** * Label displayed when a value is selected in the ComboBox * This label can either be an input (when editable or expanded) or a simple span */ export function ComboboxSelection({ labelRenderer, placeholder, search, expanded, disabled, readOnly, focused, onChange, selectedIndex, options, editable, labelId, id, classNamePrefix, invalid, required, }: ComboboxSelectionProps) { const showLabel = !editable || !expanded; const selectedOption = selectedIndex === undefined ? undefined : options[selectedIndex]; const LabelSelectionComponent = labelRenderer ?? ComboboxLabelSelection; return (
{showLabel ? ( ) : ( ) => onChange?.(e.target.value ?? e.target.innerText) } value={search} placeholder={placeholder} disabled={disabled} readOnly={readOnly} focused={focused} labelledBy={labelId} required={required} /> )}
); }