Setting values

Values can change in a couple of different ways: through defaults, interacting with the UI or programmatically. The select defaults to null (nothing is selected), which can be easily overridden with the defaultSelection option. The values are set by interacting with the component and making a selection or it can be done programmatically. Use the buttons option for showing/hiding set, cancel or add custom buttons.

Get started with this example

Demo

Controlling the default value

The select has no selected value by default. You can however manually set a default value through the defaultSelection option. This value will show as selected when opening the control, but it needs to be submitted to be accepted as a selected value.

const myData = [
    { text: 'Atlanta', value: 'atl' },
    { text: 'Berlin', value: 'ber' },
    { text: 'Boston', value: 'bos' },
    { text: 'Chicago', value: 'chi' },
    { text: 'London', value: 'lon' }
];

<Select
    data={myData}
/>
const myData = [
    { text: 'Atlanta', value: 'atl' },
    { text: 'Berlin', value: 'ber' },
    { text: 'Boston', value: 'bos' },
    { text: 'Chicago', value: 'chi' },
    { text: 'London', value: 'lon' }
];

const myDefault = 'ber';

<Select
    data={myData}
    defaultSelection={myDefault}
/>
Setting values runtime

While the selected value can be changed by interacting with the select, you can set the state value to change it programmatically.

jsxconst [myValue, setMyValue] = React.useState(null);
const setBoston = (event) => {
    setMyValue('bos');
};
const setLondon = (event) => {
    setMyValue('lon');
};

<Button onClick={setBoston}>Boston</Button>
<Button onClick={setLondon}>London</Button>
<Select
    data={myData}
    value={myValue}
/>
Setting values with buttons

The button API provides shortcuts to value selection and confirmation. Add a custom button and/or remove the 'Set' button to activate auto-set, which automatically closes the dialog if a value is selected.

jsxconst myData = [
    { text: 'Atlanta', value: 'atl' },
    { text: 'Berlin', value: 'ber' },
    { text: 'Boston', value: 'bos' },
    { text: 'Chicago', value: 'chi' },
    { text: 'London', value: 'lon' }
];
const myRef = React.useRef();
const customButtons = React.useMemo(() => {
    return [{
            text: 'Custom',
            handler: () => {
                myRef.current.setTempVal('chi');
            }
        }, 'set', 'cancel'
    ]
}, []);
                            
<Select
    data={myData}
    buttons={customButtons}
    ref={myRef}
/>
jsxconst myData = [
    { text: 'Atlanta', value: 'atl' },
    { text: 'Berlin', value: 'ber' },
    { text: 'Boston', value: 'bos' },
    { text: 'Chicago', value: 'chi' },
    { text: 'London', value: 'lon' }
];
                            
<Select
    data={myData}
    buttons={['cancel']}
/>

Duplicate Session

You have signed in on a different machine. To keep everything in sync, you have been signed out of this session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.

Duplicate Session

We noticed you are logged in on a different machine and have closed your old session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.