-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAdaptiveSelect.jsx
More file actions
30 lines (27 loc) · 871 Bytes
/
Copy pathAdaptiveSelect.jsx
File metadata and controls
30 lines (27 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import React from 'react';
import MenuItem from '@material-ui/core/MenuItem';
import NativeSelect from '@material-ui/core/NativeSelect';
import Select from '@material-ui/core/Select';
import { isMobile } from 'react-device-detect';
const AdaptiveSelect = (props) => {
const { options, value, onChange } = props;
if (!options || !value) return null;
return isMobile ? (
<NativeSelect value={value} onChange={e => onChange(e.target.value)}>
{Object.keys(options).map(key => (
<option key={key} value={key}>
{options[key]}
</option>
))}
</NativeSelect>
) : (
<Select value={value} onChange={e => onChange(e.target.value)}>
{Object.keys(options).map(key => (
<MenuItem key={key} value={key}>
{options[key]}
</MenuItem>
))}
</Select>
);
};
export default AdaptiveSelect;