Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material UI Autocomplete accept custom values

I have this autocomplete drop down box.

If I select values other than in the drop down, how do i accept the autocomplete drop down box to take in the custom value. In this example, bar and bat values are in drop down.

How do i accept bag to be accepted as input value?

my code is at : https://codesandbox.io/s/material-demo-8scos

export default function ComboBox() {
    return (
    <Autocomplete
        id="combo-box-demo"
       options={top100Films}
       getOptionLabel={option => option.title}
       style={{ width: 300 }}
       renderInput={params => (
           <TextField {...params} label="Combo box" variant="outlined" />
       )}
    />
  );
}

const top100Films = [
  { title: "bar", year: 1994 },
  { title: "bat", year: 1972 }
];

https://codesandbox.io/s/material-demo-ytrt4

like image 768
Rahul SK Avatar asked Oct 19 '25 20:10

Rahul SK


1 Answers

https://mui.com/material-ui/react-autocomplete/

Just add freeSolo after the Autocomplete.

like image 56
Alex Bran Avatar answered Oct 21 '25 11:10

Alex Bran