Can anyone help me to reduce the height of Material UI Autocomplete component ? I am trying to use set the height property to 10 or 20 px though the classes property. But it does nothing. Also tried to reduce the height of the Textfield which wrapped by Autocomplete component, but when I tried to reduce the height of the Textfield component through InputProps, then the Items that were to be suggested in Autocomplete area don't display.
The React AutoComplete is a textbox component that provides a list of suggestions to select from as the user types. It has several out-of-the-box features such as data binding, filtering, grouping, UI customization, accessibility, and more.
By default, it'll have the initial value set into the TextField of the Autocomplete component but when the user makes any modifications, it calls up the Autocomplete options depending on the dataSource prop.
There are two versions of the autocomplete that can be used: Combo box — Where the value of the text input must be chosen from a predefined set of values. Free solo — Where the text input can contain any value but is suggested from a list of possible values.
I am also customizing the Autocomplete
component.
To reduce the height, I used the size
attribute and removed the label
attribute.
renderInput={(params) => <TextField {...params} variant="standard" size="small" />}
Make sure not to override the params
provided by the Autocomplete component on your TextField component, which already include things like InputProps
.
You'll probably want to use Autocomplete's CSS API to achieve all the customizations you're looking for. For example,
const useStyles = makeStyles(theme => ({
inputRoot: {
color: theme.palette.primary.contrastText,
},
popupIndicator: {
color: theme.palette.primary.contrastText,
},
root: {
padding: `0 ${theme.spacing(1)}px`,
},
}))
const AutocompleteWrapper = ({
value,
onChange,
options,
}) => {
const classes = useStyles()
return (
<Autocomplete
classes={classes}
options={options}
value={value}
onChange={onChange}
renderInput={(params) => <TextField {...params} variant="standard" size="small" />}
/>
)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With