您必须将样式传递给 classes 属性才能更改 TableRow 的样式。
要实现 background-color 更改,您需要覆盖默认类:.MuiTableRow-root.Mui-selected 和 .MuiTableRow-root.Mui-selected:hover。
要覆盖它们,您必须在 makeStyles 挂钩中使用带有所谓的 $ruleName 的父引用。 Here is a very good explanation from @Ryan Cogswell if you are more interested how it works.
这将如下所示:
const useStyles = makeStyles((theme) => ({
// your other styles
...,
tableRowRoot: {
"&$tableRowSelected, &$tableRowSelected:hover": {
backgroundColor: theme.palette.primary.main
}
},
tableRowSelected: {
backgroundColor: theme.palette.primary.main
}
}));
...
<TableRow
// your other props
...
classes={{
root: classes.tableRowRoot,
selected: classes. tableRowSelected,
}}
>
...
</TableRow>;
对于复选框,您只需添加 color 属性即可更改它:
<Checkbox
// other props
...
color="primary"
/>
对于您的Toolbar,您只需更改useToolbarStyles 中提供的highlight 类即可使事情正常进行:
import { alpha } from "@material-ui/core/styles";
...
const useToolbarStyles = makeStyles((theme) => ({
...,
highlight:
theme.palette.type === "light"
? {
color: theme.palette.primary.main,
backgroundColor: alpha(
theme.palette.primary.light,
theme.palette.action.selectedOpacity
)
}
: {
color: theme.palette.text.primary,
backgroundColor: theme.palette.primary.dark
},
}));
现场演示: