score:4

Accepted answer

you should be specifying the variant on the formcontrol element instead of on the select element. with putting it on the select, the inputlabel element is not getting the appropriate styling for the "filled" variant.

here's the beginning of the "filled" style for inputlabel:

  /* styles applied to the root element if `variant="filled"`. */
  filled: {
    // chrome's autofill feature gives the input field a yellow background.
    // since the input field is behind the label in the html tree,
    // the input field is drawn last and hides the label with an opaque background color.
    // zindex: 1 will raise the label above opaque background-colors of input.
    zindex: 1,

note the comment indicating that the z-index is needed to raise the label above opaque background colors (as you are setting on the select).

here's a working example demonstrating the variant on the formcontrol:

import react from "react";
import { makestyles } from "@material-ui/core/styles";
import inputlabel from "@material-ui/core/inputlabel";
import menuitem from "@material-ui/core/menuitem";
import formcontrol from "@material-ui/core/formcontrol";
import select from "@material-ui/core/select";

const usestyles = makestyles((theme) => ({
  formcontrol: {
    margin: theme.spacing(1),
    minwidth: 120
  },
  selectempty: {
    margintop: theme.spacing(2)
  }
}));

export default function simpleselect() {
  const classes = usestyles();
  const [age, setage] = react.usestate("");

  const handlechange = (event) => {
    setage(event.target.value);
  };

  return (
    <div>
      <formcontrol
        variant="filled"
        size="small"
        classname={classes.formcontrol}
      >
        <inputlabel
          style={{ color: "#000" }}
          id="demo-simple-select-filled-label"
        >
          age
        </inputlabel>
        <select
          style={{ backgroundcolor: "rgb(232, 241, 250)" }}
          labelid="demo-simple-select-filled-label"
          id="demo-simple-select-filled"
          value={age}
          onchange={handlechange}
        >
          <menuitem value="">
            <em>none</em>
          </menuitem>
          <menuitem value={10}>ten</menuitem>
          <menuitem value={20}>twenty</menuitem>
          <menuitem value={30}>thirty</menuitem>
        </select>
      </formcontrol>
    </div>
  );
}

edit filled select with background color


Related Query

More Query from same tag