I try to achieve a dropdown that displays multiple buttons for selection and a display value independent of the drop-down items like so:
In this example, the user can select different scales for a chart that displays two metrics. In case both metrics have different scales, the drop-down shows "mixed" in case they both have the same scale it shall show either "linear" or "log", depending on the overall scale.
I tried with MUI Select component and added a custom function to change the display value, but I get the warning:
MUI: You have provided an out-of-range value `linear` for the select component.
Consider providing a value that matches one of the available options or ''.
Here my code snippets:
const displayMetricScale = () => {
return (scale_metric1===scale_metric2) ? (scale_metric1) : "mixed";
};
<Select
label="Scale"
value={displayMetricScale()}
defaultValue="mixed"
renderValue={(p) => p}
>
<MenuItem>
<FormControl>
<FormLabel>Metric 1</FormLabel>
<Button onClick={changeScaleLin} >
Linear
</Button>
<Button onClick={changeScaleLog} >
Logarithmic
</Button>
</FormControl>
</MenuItem>
<MenuItem>
<FormControl>
<FormLabel>Metric 2</FormLabel>
<Button onClick={changeScaleLin} >
Linear
</Button>
<Button onClick={changeScaleLog} >
Logarithmic
</Button>
</FormControl>
</MenuItem>
</Select>
