You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
orario/src/components/ComboBox.jsx

29 lines
793 B
React

2 years ago
import { useRef, useState } from 'preact/hooks'
import { Icon } from './Icon.jsx'
2 years ago
let ids = 0
function generateId() {
return 'combo-id-' + ids++
}
export const ComboBox = ({ options, value, setValue }) => {
const [uid] = useState(() => generateId())
const selectRef = useRef()
return (
2 years ago
<div class="input-combo">
<select ref={selectRef} id={uid} onInput={e => setValue(e.target.value)}>
{options.map(option => (
<option value={option.value} selected={option.value === value}>
{option.label}
</option>
))}
</select>
2 years ago
<label class="icon" for={uid}>
<Icon name="expand_more" />
</label>
</div>
)
}