我正在try 为material ui select组件实现自己的图标.到目前为止,我已经使用"IconComponent"MU select属性更改了默认图标.
但是,当菜单列表打开时,新图标不会旋转,就像默认图标一样,而且,具有值的菜单在单击时不会打开.仅当我单击" Select 组件"本身,而不是"新建"图标时,才会显示ListItem.
我测试了两个不同的图标(anotherIcon和newIcon),问题依然存在.
const newIcon = (
<svg
width="38"
height="38"
viewBox="0 0 38 38"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<rect x="0.5" y="0.5" width="37" height="37" rx="9.5" stroke="#222426" />
<svg
width="18"
height="12"
x="10"
y="13"
viewBox="0 0 18 12"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M0.66732 0.999999L8.72964 10.8681C8.76363 10.9095 8.80536 10.9428 8.85208 10.9655C8.89879 10.9882 8.94943 11 9.00065 11C9.05187 11 9.10251 10.9882 9.14922 10.9655C9.19594 10.9428 9.23767 10.9095 9.27167 10.8681L17.334 1"
stroke="#222426"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</svg>
);
<FormControl fullWidth>
<InputLabel id="demo-simple-select-label">Age</InputLabel>
<Select
labelId="demo-simple-select-label"
id="demo-simple-select"
value={age}
label="Age"
onChange={handleChange}
IconComponent={() => <div className="test">{newIcon}</div>}
>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
</FormControl>
我还try 手动超速 Select iconOpen类,以获得180度的图标变换和旋转(如本例中的React JS Material UI Select IconComponent (Dropdown Icon) avoid rotating度) 但它也没有起作用.
有人知道为什么新图标不旋转,以及如何解决这个问题,以及在点击新图标时打开菜单吗?
这里是演示:https://codesandbox.io/s/basicselect-material-demo-forked-d946k1?file=/demo.js