reactjs - 如何更改下拉悬停颜色 react Material-UI Select

标签 reactjs user-interface material-ui

我需要将下拉悬停更改为绿色。我尝试了内联 CSS 和 makeStyle(),但这些都不适合我。我不知道要更改此悬停颜色。如果有人可以帮助我解决这个问题,我将不胜感激。

enter image description here

我需要将悬停颜色更改为绿色。 这是我的代码:-

                        <Select
                            className={dropDowStyle.select}
                            style={{
                                borderRadius: '8px', marginLeft: '-150px',
                                width: '163px', height: '45px', fontSize: '15px',
                                backgroundColor: "transparent",borderColor:primaryColor + "88"
                            }}
                            sx={{width: 163}}
                            // defaultValue=""
                            input={<OutlinedInput style={{borderColor: primaryColor + "88",}}/>}
                            displayEmpty
                            value={city}
                            renderValue={(value) => {
                                return (
                                    <Box sx={{display: "flex", gap: 2.5}}>
                                        <SvgIcon style={{fontSize: '20px'}}>
                                            <LocationOnIcon/>
                                        </SvgIcon>
                                        {renderLocation && value}
                                    </Box>
                                );
                            }}
                            onChange={cityValueHandler}
                        >

                            {shopLocation.map((option) => (
                                <MenuItem key={option.gg} value={option.gg}>
                                    {option.gg}
                                </MenuItem>
                            ))}
                        </Select>

最佳答案

菜单列表的容器是 Paper,它是 Menu 的一部分(Select 的下拉菜单)。您可以像下面这样定位嵌套组件的 Prop 。参见 here Menu 类名列表。也看看所有 classNames对于组件状态。

<Select
  // to override the border color of the Select input
  sx={{
    "&:hover": {
      "&& fieldset": {
        border: "3px solid green"
      }
    }
  }}
  // to override the color of the dropdown container
  MenuProps={{
    PaperProps: {
      sx: {
        "& .MuiMenuItem-root.Mui-selected": {
          backgroundColor: "yellow"
        },
        "& .MuiMenuItem-root:hover": {
          backgroundColor: "pink"
        },
        "& .MuiMenuItem-root.Mui-selected:hover": {
          backgroundColor: "red"
        }
      }
    }
  }}

现场演示

Codesandbox Demo

关于reactjs - 如何更改下拉悬停颜色 react Material-UI Select,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69436218/

相关文章:

javascript - 尝试获取数据来创建菜单,getStaticProps 返回未定义

python - 动态调整大小并向 Tkinter 窗口添加小部件

reactjs - React DnD 拖动时显示整个列表

reactjs - mui中如何对齐图标和文本

javascript - 如何修复 React Redux 和 React Hook useEffect 缺少依赖项 : 'dispatch'

reactjs - 在 props 中传递对象,使用 typescript 进行 ReactJS

java - JRadioButton java

java - SwingWorker 问题

css - MUI 进度指示器居中水平对齐

javascript - 为什么 Material-UI Appbar onLeftIconButtonTouchTap 不起作用?