1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2024-07-02 20:30:27 +00:00
foris-js/src/bootstrap/Select.md
2019-08-27 11:54:57 +02:00

656 B

Select with options Bootstrap component input with label and predefined sizes and structure for using in foris forms.

All additional props are passed to the <select> HTML component.

import {useState} from 'react';
const CHOICES={
    apple:'Apple',
    banana:'Banana',
    peach:'Peach',
};
const [value, setValue] = useState(Object.keys(CHOICES)[0]);

<>
    {/*Yeah, it gets event, not value!*/}
    <Select
        label="Fruit"
        value={value}
        choices={CHOICES}
        onChange={event=>setValue(event.target.value)}
    />
    <p>Selected choice label: {CHOICES[value]}</p>
    <p>Selected choice value: {value}</p>
</>