ReactJS: How to change placeholder font size of Material Ui Autocomplete?

20k Views Asked by At

I want to change the placeholder fontsize of Material Ui Autocomplet. Is there any way?

enter image description here

             <Autocomplete
                  multiple
                  id="tags-outlined"
                  options={top100Films}
                  getOptionLabel={(option) => option.title}
                  defaultValue={[top100Films[13]]}
                  filterSelectedOptions
                  size="small"

                  renderInput={(params) => (
                    <TextField
                      {...params}
                     
                      variant="outlined"

                      placeholder="Enter Transshipment Ports"

                      
                    />
                  )}
                />
3

There are 3 best solutions below

1
On BEST ANSWER

In your example, you can target the input element of the component you render in renderInput which is TextField using makeStyles

const useStyles = makeStyles({
  customTextField: {
    "& input::placeholder": {
      fontSize: "20px"
    }
  }
})

<TextField
  classes={{ root: classes.customTextField }}
  {...params}
  variant="outlined"
  placeholder="Enter Transshipment Ports"
/>

Example below using forked MUI demo

Edit Material demo (forked)

1
On

You can just add the ::placeholder css to the class/id of the input field, and change the font-size

Example:

#tags-outlined::placeholder {
   font-size: 14px;
}
0
On

The sx property allows users to override the styling applied to the MuiFormLabel-root object, including the font size. This is useful for creating custom labels that better suit the user's design needs.

<TextField
        {...props}
        sx={{
          '& .MuiFormLabel-root': {
            fontSize: '0.8rem',
          },
        }}
      />