Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
Material UI: Select is collapsed, autoWidth not working

The Material UI (React) Select item is collapsed and doesn't auto expand in width despite autoWidth.

enter image description here

   <FormControl margin="dense">
          <InputLabel id="prefix-label">Prefix</InputLabel>
          <Select
           autoWidth
           labelId="prefix-label"
           id="prefix"
           disabled={formPrefix.disabled}
           value={formPrefix.value ?? ""}
           error={formPrefix.invalid}
           defaultValue={""}
           label="Prefix"
           onChange={handlePrefix}
          >
                 <MenuItem value={""} disabled>
                        Prefix
                 </MenuItem>
                 <MenuItem value={"US"}>US +1</MenuItem>
                 <MenuItem value={"else"}>Else</MenuItem>
          </Select>
          <FormHelperText></FormHelperText>
   </FormControl>

Am I doing something wrong here?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You should add width property to sx prop of FormLabel like:

<FormControl margin="dense" sx={{ width: 100 }}>

You can take a look at this sandbox for live working example.

about 4 years ago · Juan Pablo Isaza Report

0

Add the fullWidth props on <FormControl> component instead of on the <Select> component.

Your JSX code has to be like this

<FormControl margin="dense" fullWidth>
  <InputLabel id="prefix-label">Prefix</InputLabel>
  <Select
    // autoWidth
    // fullWidth
    labelId="prefix-label"
    id="prefix"
    //  disabled={formPrefix.disabled}
    //  value={formPrefix.value ?? ""}
    //  error={formPrefix.invalid}
    defaultValue={""}
    label="Prefix"
    //  onChange={handlePrefix}
  >
    <MenuItem value={""} disabled>
      Prefix
    </MenuItem>
    <MenuItem value={"US"}>US +1</MenuItem>
    <MenuItem value={"else"}>Else</MenuItem>
  </Select>
  <FormHelperText></FormHelperText>
</FormControl>

Edit this code in the CodeSandbox

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!