How to fix Material-UI Select w/ MenuItem where MenuItem being rendered horizontally?

Viewed 223

I've been playing with Material-UI with React/Next.js and I'm running across a weird and persistent bug. I can't get the <Select> to render a regular vertical dropdown menu. How do I get the <MenuItem>s to render vertically?

I searched the docs and can't find anything. It's also worth noting my code is pretty much the same as the example:

render (
    <div>
        <FormControl
            fullWidth
            style={{
            paddingBottom: formError
                ? `${paddingBeneathFormControls}px`
                : `${paddingBeneathFormControls + 22}px`,
            }}
        >
            <InputLabel id="demo-simple-select-label">Age</InputLabel>
            <Select
            className="test"
            labelId="demo-simple-select-label"
            label="Age"
            value={10}
            >
            <MenuItem value={10}>Ten</MenuItem>
            <MenuItem value={20}>Twenty</MenuItem>
            <MenuItem value={30}>Thirty</MenuItem>
            </Select>
            {formError && (
            <FormHelperText error>
                Please enter a valid value.
            </FormHelperText>
            )}
        </FormControl>
    </div>
)

Output Screenshot

1 Answers

There may be some unexpected side-effects for others, but I found a solution to my problem. I was using @mui/material library, which I figured was the more modern version - they say NASA, Netflix, Spotify and others use this library. I simply changed my import to @material-ui/core, which exposes the same elements I was using (Select, MenuItem, FormControl, FormHelperText, InputLabel, TextField). I'm not entirely sure where these two libraries differ but in my case simply switching that made all my code work.

It's worth noting that using both adds some conflicting styling behavior - I tried at first to only borrow the Select and MenuItem components from @material-ui/core, but when I imported that library it broke the component styling for @mui/material components.

Related