我正在使用 material-ui 的选择框组件,想要将下拉箭头图标替换为其他字体图标。如何实现?我没有找到覆盖此样式的选项。
我正在使用 material-ui 的选择框组件,想要将下拉箭头图标替换为其他字体图标。如何实现?我没有找到覆盖此样式的选项。
import Select from '@material-ui/core/Select';
import Person from '@material-ui/icons/Person';
<Select
IconComponent={() => (
<Person />
)}>
此外,如果图标无法点击,则需要在CSS中加入以下代码:{ pointer-events: none }
现如今,对我来说最好的方法就是
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"'
。 - ZacIconComponent={(props) => (<ExpandMoreOutlinedIcon {...props}/>)}
const HomeIcon = (props) => (
<SvgIcon {...props}>
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z" />
</SvgIcon>
);
<SelectField
dropDownMenuProps={{
iconButton:<HomeIcon />,
}}
/>
如果您要将它传递给其他组件(例如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,
}}
/>
const AtomDropDown = React.forwardRef<HTMLButtonElement, any>(
({ Icon }, ref): JSX.Element => {
return (
<NativeSelect
IconComponent={() => {
return Icon ? Icon : <KeyboardArrowDownIcon />
}}
>
{options.map((option: any) => {
return <option value={option.key}>{option.name}</option>
})}
</NativeSelect>
</div >
)
}
);
export default AtomDropDown;
使用方法:
import {AtomDropDown} from '@/components/atom/dropdown/index';
<AtomDropDown
Icon={<KeyboardArrowDownIcon/>}
/>
{ pointer-events: none }
,但图标仍然无法点击。有什么想法吗? - Inaara Kalani