utopia-ui/lib/src/Components/Input/ComboBoxInput.tsx

30 lines
642 B
TypeScript

interface ComboBoxProps {
id?: string
options: string[]
value: string
onValueChange: (newValue: string) => void
}
const ComboBoxInput = ({ id, options, value, onValueChange }: ComboBoxProps) => {
const handleChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
onValueChange(e.target.value)
}
return (
<select
id={id}
className='tw:select tw:w-full'
onChange={handleChange}
value={value} // ← hier controlled statt defaultValue
>
{options.map((o) => (
<option value={o} key={o}>
{o}
</option>
))}
</select>
)
}
export default ComboBoxInput