The syntax for attribute selectors is largely the same as in CSS. &
is used to refer to the generated class (classes.myCheckboxStyles
in my example below) and then further selectors can be added within the quotes (e.g. "&[aria-checked=true]"
).
Below is a working example demonstrating the syntax:
import React from "react";
import { makeStyles } from "@material-ui/core/styles";
const useStyles = makeStyles({
myCheckboxStyles: {
border: "1px black solid",
color: "white",
"&[aria-checked=true]": {
backgroundColor: "blue"
}
}
});
export default function Checkboxes() {
const classes = useStyles();
const [checked, setChecked] = React.useState(false);
return (
<div>
<span
onClick={() => setChecked(!checked)}
aria-checked={checked}
className={classes.myCheckboxStyles}
>
X
</span>
</div>
);
}
