Group options
Enable group headers through the group property of the options or the optgroup of the native select.
Grouping works for both single and multiple select pickers.
Demo
Group headers with single select
const myData = [
{ text: 'Atlanta', group: 'US', value: 'atl' },
{ text: 'Boston', group: 'US', value: 'bos' },
{ text: 'Bath', group: 'UK', value: 'bat' },
{ text: 'Bristol', group: 'UK', value: 'bri' },
];
<Select
data={myData}
touchUi=
/>
Render a group wheel
const myData = [
{ text: 'Atlanta', group: 'US', value: 'atl' },
{ text: 'Boston', group: 'US', value: 'bos' },
{ text: 'Bath', group: 'UK', value: 'bat' },
{ text: 'Bristol', group: 'UK', value: 'bri' },
{ text: 'Berlin', group: 'DE', value: 'ber' },
{ text: 'Duisburg', group: 'DE', value: 'dus' },
{ text: 'Cologne', group: 'DE', value: 'col' },
{ text: 'Paris', group: 'FR', value: 'par' },
{ text: 'Lyon', group: 'FR', value: 'lyo' },
];
<Select
showGroupWheel={true}
data={myData}
touchUi=
/>
Group headers with multiple select
const myData = [
{ text: 'Camera & Photo', group: 'Electronics', value: 1 },
{ text: 'Cell Phones & Accessories', group: 'Electronics', value: 2 },
{ text: 'GPS & Navigation', group: 'Electronics', value: 3 },
{ text: 'Plugs and Outlets', group: 'Smart Home', value: 4 },
{ text: 'Heating and Cooling', group: 'Smart Home', value: 5 },
{ text: 'Detectors and Sensors', group: 'Smart Home', value: 6 },
];
<Select
data={myData}
touchUi=
/>
JSXTSX
import { Select, setOptions } from '@mobiscroll/react';
import { useMemo } from 'react';
setOptions({
locale: ,
theme: ' ',
themeVariant: ' '
});
function App() {
const singleData = useMemo(
() => [
{ text: 'Atlanta', group: 'US', value: 'atl' },
{ text: 'Boston', group: 'US', value: 'bos' },
{ text: 'Bath', group: 'UK', value: 'bat' },
{ text: 'Bristol', group: 'UK', value: 'bri' },
{ text: 'Berlin', group: 'DE', value: 'ber' },
{ text: 'Duisburg', group: 'DE', value: 'dus' },
{ text: 'Cologne', group: 'DE', value: 'col' },
{ text: 'Paris', group: 'FR', value: 'par' },
{ text: 'Lyon', group: 'FR', value: 'lyo' },
],
[],
);
const multipleData = useMemo(
() => [
{ text: 'Camera & Photo', group: 'Electronics', value: 1 },
{ text: 'Cell Phones & Accessories', group: 'Electronics', value: 2 },
{ text: 'GPS & Navigation', group: 'Electronics', value: 3 },
{ text: 'Plugs and Outlets', group: 'Smart Home', value: 4 },
{ text: 'Heating and Cooling', group: 'Smart Home', value: 5 },
{ text: 'Detectors and Sensors', group: 'Smart Home', value: 6 },
],
[],
);
return (
<>
<Select data={singleData} label="Single select" inputStyle="outline" labelStyle="stacked" placeholder="Please select..." />
<Select
data={singleData}
label="Group wheel"
showGroupWheel={true}
inputStyle="outline"
labelStyle="stacked"
placeholder="Please select..."
/>
<Select
data={multipleData}
selectMultiple={true}
label="Multi-select"
inputStyle="outline"
labelStyle="stacked"
placeholder="Please select..."
/>
</>
);
}
export default App;
import { Select, setOptions } from '@mobiscroll/react';
setOptions({
locale: ,
theme: ' ',
themeVariant: ' '
});
const singleData = [
{ text: 'Atlanta', group: 'US', value: 'atl' },
{ text: 'Boston', group: 'US', value: 'bos' },
{ text: 'Bath', group: 'UK', value: 'bat' },
{ text: 'Bristol', group: 'UK', value: 'bri' },
{ text: 'Berlin', group: 'DE', value: 'ber' },
{ text: 'Duisburg', group: 'DE', value: 'dus' },
{ text: 'Cologne', group: 'DE', value: 'col' },
{ text: 'Paris', group: 'FR', value: 'par' },
{ text: 'Lyon', group: 'FR', value: 'lyo' },
];
const multipleData = [
{ text: 'Camera & Photo', group: 'Electronics', value: 1 },
{ text: 'Cell Phones & Accessories', group: 'Electronics', value: 2 },
{ text: 'GPS & Navigation', group: 'Electronics', value: 3 },
{ text: 'Plugs and Outlets', group: 'Smart Home', value: 4 },
{ text: 'Heating and Cooling', group: 'Smart Home', value: 5 },
{ text: 'Detectors and Sensors', group: 'Smart Home', value: 6 },
];
function App() {
return (
<>
<Select data={singleData} label="Single select" inputStyle="outline" labelStyle="stacked" placeholder="Please select..." />
<Select
data={singleData}
label="Group wheel"
showGroupWheel={true}
inputStyle="outline"
labelStyle="stacked"
placeholder="Please select..."
/>
<Select
data={multipleData}
selectMultiple={true}
label="Multi-select"
inputStyle="outline"
labelStyle="stacked"
placeholder="Please select..."
/>
</>
);
}
export default App;