1

I am trying to customize the positioning of the Select component which opens the menu as a modal by default. I need a way to make it render inline below the controlling input. I have found this library https://iulian-radu-at.github.io/react-select-material-ui/?path=/story/reactselectmaterialui--with-and-without-fullwidth-set based on Material-UI Select, though it unfortunately doesn't work for me as I have a lot of custom styling built for my component. I have seen that the ButtonGroup component can somewhat achieve this, though I would like to avoid that as an option, because of the custom styling that I have already done. I would love to hear any suggestions, I am sure I am not the only person who has this problem. Thanks!


const useStyles = makeStyles((theme) => ({
  root: {
    backgroundColor: theme.palette.background.white,
    margin: theme.spacing(1),
    width: ({ inputWidth }) => (inputWidth ? inputWidth : `inherit`),
  },
}))

export const Dropdown = ({
  serviceIndex,
  label,
  fieldName,
  value,
  inputWidth,
  options,
  updateValue,
}) => {
  const classes = useStyles({ inputWidth })

  const handleChange = (event) => {
    /* logic handling updates here */
  }

  return (
    <FormControl variant="outlined" className={classes.root}>
      <Box>
        <InputLabel id={`select-outlined-${label}-${serviceIndex}`}>
          {label}
        </InputLabel>
      </Box>
      <Select
        labelId={`select-outlined-label-${label}-${serviceIndex}`}
        id={`select-outlined-label-${label}-${serviceIndex}`}
        value={value || options[0]}
        onChange={handleChange}
        label={label}
      >
        {_.map(options, (option, i) => (
          <MenuItem key={i} value={option}>
            {option}
          </MenuItem>
        ))}
      </Select>
    </FormControl>
  )
}
2
  • Why arent you using material ui’s built in select? Commented Oct 3, 2020 at 22:05
  • This snippet shows that I am using it. If you are referring to another component, can you please share a link/example? Commented Oct 4, 2020 at 20:00

2 Answers 2

1

After researching this further, I found a component in the Material-UI library that will get the job done. https://material-ui.com/api/autocomplete/

Sign up to request clarification or add additional context in comments.

Comments

0

I Understand your pain .please try this code.You can write your custom styles inside the select . enjoy !

const useStyles = makeStyles((theme: any) => ({
        select: {
                height: 300,
                overflowX: 'hidden',
                overflowY: 'auto',
                }
 }))
    
         <FormControl variant="outlined"
                        className={classes.formControl}>
                        <InputLabel
                            id="demo-simple-select-outlined-label"
                        >Production Order Id</InputLabel>
                        <Select
                            labelId="demo-simple-select-outlined-label"
                            id="demo-simple-select-outlined"
                            value={poMenu}
                            onChange={handleChangepoSelect}
                            label="Production Order Id"
                            fullWidth
                            margin="dense"
                            MenuProps={{ classes: { paper: classes.select } }} >
                            {poSelectMenu.map((option: string, i: number) =>
                                <MenuItem key={i} value={option}>{option}</MenuItem>
                            )}
                        </Select>
                    </FormControl>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.