【问题标题】:Material Ui Automcomplete Clear icon style材质 UI 自动完成清除图标样式
【发布时间】:2021-05-11 08:05:12
【问题描述】:

我想更改清除图标的颜色,我尝试过this,但它会删除带有静态图标的图标。我只是想改变颜色。

        <Autocomplete className={`${commonClasses.searchBarMobileScreen}`}
          id="product-search"
          forcePopupIcon={false}
          classes={searchTextColor()}
          options={options.sort((a, b) => -b.name.localeCompare(a.name))}
          groupBy={(option) => option.cid}
          getOptionLabel={(option) => (`${option.brand} ${option.name}`)}
          renderInput={(params) => <SearchTextField
            fullWidth
            {...params}
            label="Search..."
            variant="outlined"
            InputLabelProps={{
              classes: {
                root: commonClasses.whiteColor,
              }
            }}
          />}
        />

【问题讨论】:

    标签: reactjs autocomplete material-ui


    【解决方案1】:

    您可以向 clearIndicator 添加一些样式。全局类是.MuiAutocomplete-clearIndicator

    import React from "react";
    import { makeStyles } from "@material-ui/core/styles";
    import Autocomplete from "@material-ui/lab/Autocomplete";
    import TextField from "@material-ui/core/TextField";
    
    const useStyles = makeStyles((theme) => ({
      inputRoot: {
        color: "blue",
        fontFamily: "Roboto Mono",
        backgroundColor: "#f2f2f2",
        "& .MuiOutlinedInput-notchedOutline": {
          borderWidth: "2px",
          borderColor: "blue"
        },
        "&:hover .MuiOutlinedInput-notchedOutline": {
          borderWidth: "2px",
          borderColor: "blue"
        },
        "&.Mui-focused .MuiOutlinedInput-notchedOutline": {
          borderWidth: "2px",
          borderColor: "blue"
        }
      },
      clearIndicator: {
        color: "red"
      }
    }));
    
    export default function ComboBox() {
      const classes = useStyles();
    
      return (
        <Autocomplete
          id="combo-box-demo"
          classes={classes}
          options={[1,2,3]}
          forcePopupIcon
          getOptionLabel={(option) => option.title}
          renderInput={(params) => {
            return (
              <TextField
                {...params}
                label="Combo box"
                variant="outlined"
                fullWidth
              />
            );
          }}
        />
      );
    }
    

    【讨论】:

    猜你喜欢
    • 2021-11-10
    • 2020-04-11
    • 1970-01-01
    • 2020-04-09
    • 1970-01-01
    • 2020-08-08
    • 2021-12-18
    • 2021-04-27
    • 2019-11-25
    相关资源
    最近更新 更多