【发布时间】:2018-10-04 05:15:05
【问题描述】:
我正在使用 material-ui 选择字段。我想将给定的下拉图标更改为不同的字体图标。如何做到这一点?我没有看到任何替代这种风格的选择
【问题讨论】:
标签: reactjs dropdown material-ui
我正在使用 material-ui 选择字段。我想将给定的下拉图标更改为不同的字体图标。如何做到这一点?我没有看到任何替代这种风格的选择
【问题讨论】:
标签: reactjs dropdown material-ui
const HomeIcon = (props) => (
<SvgIcon {...props}>
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z" />
</SvgIcon>
);
<SelectField
dropDownMenuProps={{
iconButton:<HomeIcon />,
}}
/>
您可以覆盖 dropDownMenuProps 以呈现不同的图标
【讨论】:
在最新的 Material-ui v1.4.0 中。有一个属性 IconComponent 可以接收函数:
import Select from '@material-ui/core/Select';
import Person from '@material-ui/icons/Person';
<Select
IconComponent={() => (
<Person />
)}>
另外,如果图标不可点击,则需要在css中添加
{ pointer-events: none }
【讨论】:
如果您将其传递给另一个组合。像 TablePagination 那样做
// @flow
import React from 'react';
import ChevronDownIcon from 'mdi-react/ChevronDownIcon';
<TablePagination
colSpan={3}
component="div"
count={itemsTotal}
rowsPerPage={pageSize}
page={currentPage}
rowsPerPageOptions={rowPerPageOptions}
onChangePage={handleChangePage}
onChangeRowsPerPage={handleChangeRowsPerPage}
ActionsComponent={PaginationActionsWrapped}
SelectProps={{
IconComponent: () => <ChevronDownIcon />,
}}
classes={{
root: classes.root,
select: classes.select,
selectIcon: classes.selectIcon,
caption: classes.caption,
}}
/>
【讨论】:
现在,对我来说最好的方式就是
import Select from '@material-ui/core/Select';
import Person from '@material-ui/icons/Person';
<Select
IconComponent = {Person}
/>
无需添加任何 CSS 即可完美运行。
【讨论】:
Type 'ReactElement<any, any>' is not assignable to type '"view"'
IconComponent={(props) => (<ExpandMoreOutlinedIcon {...props}/>)}
【讨论】: