reactjs - React Material UI - Override using withStyles
问题描述
I am working on a project and leverage React Material UI and need to override the Select component's border bottom color on the focused state. Here is what I'm using right now
import { Select as MuiSelect, withStyles } from '@material-ui/core';
import { BRAND_COLORS } from '../../constants/colors';
const FONT_SIZE = 20;
const Select = withStyles({
root: {
fontSize: FONT_SIZE,
'&:focus': {
backgroundColor: 'transparent',
},
'& .MuiInput-underline:after': {
borderBottomColor: BRAND_COLORS.blue,
},
},
})(MuiSelect);
export default Select;
<Select
native
startAdornment={<InputAdornment position="start"><FilterListIcon /></InputAdornment>}
value={service.regionalFocus}
onChange={(event) => this.props.changeSelectedRegionalFocus({
providerId, serviceId: service.service_id, regionalFocus:
event.target.value})
}
>
{regionalFocus.map((region, index) => service.service_regions[region.value].length ? (
<option key={index} value={region.value}>
{region.label}
</option>
) : null)}
</Select>
I'm able to override the font size, however, the borderBottomColor is not registering. Any thoughts?
解决方案
看起来您正在尝试Input
为Select
. 要覆盖道具Input
,包括样式,您需要将它们作为覆盖传递给.inputProps
Select
就像是:
const MySelect = (props) => {
return (
<Select {...props} inputProps={{ classes: { underline: props.classes.inputOverride } }}
);
};
export default withStyles({
root: {
fontSize: FONT_SIZE,
'&:focus': {
backgroundColor: 'transparent',
}
},
inputOverride: {
'&:after': {
borderBottomColor: BRAND_COLORS.blue,
}
}
})(MySelect);
文档将在此处为您提供帮助:
Select
https ://material-ui.com/api/select/ https://material-ui.com/api/input/Input
以及真正了解它是如何工作的源代码: https ://github.com/mui-org/material-ui/blob/d956b40539d7b724ca6026aeae96e1f42dd22331/packages/material-ui/src/Select/Select.js#L230
推荐阅读
- laravel - 服务器上的 Laravel 存储图像未显示
- laravel - 未定义变量:标题
- swiftui - 在 iOS 14 上获取小部件的数据
- python-3.x - 如何在python中打印最大数量的列表项和索引?
- vue.js - 如何收听在 vue js 中以编程方式创建的子事件?
- java - 如何阻止 Spring JPA 将参数转义到查询方法?
- python - 按其他列填充 NaN 值
- javascript - indexeddb 从索引 n 到索引 k 获取数据
- php - 请问如何在php MVC框架的多个文件夹中为任何类控制器动态设置命名空间
- python - 如何划分字典值?