reactjs - 如何更新material-ui按钮焦点样式?
问题描述
material-ui 引入了一种使用类名来设置组件样式的方法。我有一个如下所示的按钮组件。它使用createStyles
andwithStyles
将样式注入classes
到组件中。但我不知道如何设置Button
.
import Button from '@material-ui/core/Button';
const styles = createStyles({
button: {
minHeight: '3rem',
lineHeight: '3rem',
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-around',
fontSize: '0.8rem',
fontFamily: 'Roboto',
color: '#008091',
border: '2px solid #008091',
borderRadius: '0.375rem',
marginRight: '1rem',
marginTop: '2rem',
marginBottom: '2rem',
minWidth: '180px',
textAlign: 'center',
fontWeight: 700,
margin: '1rem 0',
padding: 0
},
selected: {
backgroundColor: '#008091',
color: 'white'
}
});
interface Props {
classes: { [className in keyof typeof styles]: string };
style?: React.CSSProperties;
text: string;
selected?: boolean;
onClick: (event: React.MouseEvent<HTMLElement>) => void;
}
const TextButton = ({ classes, style, text, onClick, selected }: Props) => {
return (
<Button
className={selected ? classNames(classes.button, classes.selected) : classes.button}
style={style}
onClick={onClick}
>
{text}
</Button>
);
};
解决方案
可以通过以下方式添加伪选择器:
const styles = createStyles({
button: {
// main styles,
"&:focus": {
color: "red"
}
}
});
推荐阅读
- http - 去块上传
- azure - 使用 Python 代码连接到我的私有 cosmos DB
- c++ - 在 C++ 中登录串行调试端口
- python - 向特定的 Discord 用户发送 DM
- angular - 单击按钮将 mat-slider 的值更改为默认值
- php - 如何使文件只能由 PHP 访问?
- reactjs - 如何在 React 中使用 onClick 保存和删除 useState 中的值?
- c++ - 柯南...[关闭]
- javascript - 如何根据键入到输入字段(例如搜索栏)中的值来更改 HTML 中 div 元素的可见性?
- css - 如何通过另一个类扩展链中的顶级选择器