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

317
Views
How to style list option in Autocomplete material ui with use of renderOption?

I am trying hard to customize option elements in autocomplete list. I want to do this by use of renderOptions prop, where i can create DOM elements. Then, i can pretty easly add styles with sx or styled components.

But something is wrong. When i try to render options list elements wrapped in divs, the names of the movies are hidden (?) They are rendered, because i can still choose option, and after that it is showned as selected, but the input list is still broken, and CSS styles are not applied.

What I am missing ? Autocomplete and its styling is new for me.

The code:

<Autocomplete
        freeSolo
        id="free-solo-2-demo"
        disableClearable
        options={top100Films.map((option) => option.title)}
        renderOption={(props, option) => {
          return (
            <li {...props}>
              <div
                sx={{
                  backgroundColor: "red",
                  color: "orange"
                }}
              >
                {option.title}
              </div>
            </li>
          );
        }}
        renderInput={(params) => (
          <TextField
            {...params}
            label="Search input"
            InputProps={{
              ...params.InputProps,
              type: "search"
            }}
          />
        )}
      />
    </Stack>
  );
}

Heres the demo : https://codesandbox.io/s/freesolo-material-demo-forked-dupxol?file=/demo.js

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

0

TL;DR Just change option.title to option in renderOption prop. And use Box instead of div to apply styles.

I couldn't find it stated in documentation explicitly but apparently each of the elements passed to options are then passed to renderOption as option argument.

So since you already pass array of option.title strings to options you will need to refer to them just as option in renderOption prop.

The sx prop is used by MUI components. So please change div to MUI Box component inside renderOption. The Box was created specifically for such cases.

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!