reactjsselectmaterial-ui

How to change the outline and label color of Mui Autocomplete Select, when it's selected


I've tried changing many of the styles through sx property, but nothing seems to work. I just want to set all colors to black, as you can see.

screenshot

<Autocomplete
                    disablePortal
                    options={top100Films}
                    sx={{
                      width: { sm: "100%", md: 340 },

                      // ALTERNATIVE 1
                      "& .MuiSvgIcon-root": {
                        color: "black",  
                      },
                      ".MuiOutlinedInput-notchedOutline": {
                        borderColor: "black",
                      },
                      "&:hover .MuiOutlinedInput-notchedOutline": {
                        borderColor: "black",
                        borderWidth: "thin",
                      },
                      "&.Mui-focused .MuiOutlinedInput-notchedOutline": {
                        borderColor: "black",
                        borderWidth: "thin",
                      },
                      "&.MuiOutlinedInput-root": {
                        "& fieldset": {
                          borderColor: "black",  
                        },
                        "&:hover fieldset": {
                          borderColor: "black",  
                        },
                        "&.Mui-focused fieldset": {
                          borderColor: "black",  
                        },
                        "&.MuiInputLabel-shrink": {
                          color: "black",
                        },
                      },
                    }}
                    renderInput={(params) => (
                      <TextField {...params} label="Movie" />
                    )}
                  />```

Solution

  • I think you need to apply styles targeting TextField as well. According to your screenshot, thats the missing part.

    ...
    
    renderInput={(params) => (
        <TextField
        {...params}
        label="Movie"
        slotProps={{
            inputLabel: { style: { color: "black" } },
        }}
        sx={{
            "& .MuiOutlinedInput-root": {
            color: "black",
            "& fieldset": { borderColor: "black" },
            "&:hover fieldset": { borderColor: "black" },
            "&.Mui-focused fieldset": { borderColor: "black" },
            },
        }}
        />
    )}
    
    ...
    

    enter image description here