简体   繁体   中英

Override react mui select dropdown style

I'm using the react mui Select Component for forms and now for language select my problem is for the language Select I need a different style for the dropdown I can do it by overriding the relevant class but the problem is it will happen to every Select and I want it only for the language Select as you can see in the photo:

在此处输入图像描述

and here my code:

const LanguagesSelect = props => {

  return (
    <Select  className="test" classes="assad" style={{ position: "relative !important", left: "20px !important", top: "30px !important", width: "168.3px !important", background: "white !important", borderRadius:"12.75px" }} >
      <MenuItem className="menuTest" style={{ paddingLeft: "5px" }}>
        <div style={{ display: "flex", width: "100%" }}>
          <img src={require("../../../assets/img/icons/flags/franch.svg").default} />
          <div style={{ marginLeft: "5px" }} >Franch</div>
        </div>
      </MenuItem>

      <MenuItem className="menuTest" style={{ paddingLeft: "5px" }}>
        <img src={require("../../../assets/img/icons/flags/eng.svg").default} />
        <div style={{ marginLeft: "5px" }}>English</div>
      </MenuItem>

      <MenuItem className="menuTest" style={{ paddingLeft: "5px" }}>
        <img src={require("../../../assets/img/icons/flags/turkish.svg").default} />
        <div style={{ marginLeft: "5px" }}>Turkish</div>
      </MenuItem>

      <MenuItem className="menuTest" style={{ paddingLeft: "5px" }}>
        <img src={require("../../../assets/img/icons/flags/czech.svg").default} />
        <div style={{ marginLeft: "5px" }}>Czech</div>
      </MenuItem>

      <MenuItem className="menuTest" style={{ paddingLeft: "5px" }}>
        <img src={require("../../../assets/img/icons/flags/hebrew.svg").default} />
        <div style={{ marginLeft: "5px" }}>עברית</div>
      </MenuItem>

    </Select>
  )

}

You can use the sx prop to override the default style. here's a link for more description mui_sx_prop

You can give external css to the Select element and manipulate the child (MenuItem) from there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM