import {FormEventHandler, forwardRef, HTMLProps, ReactNode, useId} from 'react';
export interface ComboBoxProps extends Omit, 'list'> {
onOptionSelect?: FormEventHandler;
onCustomValueInput?: FormEventHandler;
children?: ReactNode;
}
export const ComboBox = forwardRef(({
onOptionSelect,
children,
className = '',
onInput,
onCustomValueInput,
...etcProps
}, ref) => {
const id = useId();
const handleInput: FormEventHandler = (e) => {
onInput?.(e);
const nativeEvent = e.nativeEvent as unknown as { inputType?: string };
switch (nativeEvent.inputType) {
case 'deleteContentBackward':
case 'deleteContentForward':
case 'insertText':
// we type into the input
onCustomValueInput?.(e);
return;
default:
break;
// we select from the datalist
}
onOptionSelect?.(e);
}
return (
<>
>
)
})