I'm trying to create a custom consent checkbox using Material-UI v3.9.3's Checkbox.
Reason: Custom coz, the requirement is to make it with a specific background(white for the Checkbox area) and foreground(orange for the check icon) color.
Implementation so far: I've implemented it using custom CSS.
index.js
:
import React, { useState } from "react";
import { render } from "react-dom";
import Hello from "./Hello";
import Checkbox from "@material-ui/core/Checkbox";
import { withStyles, makeStyles } from "@material-ui/styles";
import "./style.css";
const useStyles = makeStyles({
checkbox: {
padding: 0,
width: 24,
height: 24
},
icon: {
borderRadius: 3,
width: 24,
height: 24,
boxShadow: "inset 0 0 0 1px rgba(16,22,26,.2), inset 0 -1px 0 rgba(16,22,26,.1)",
backgroundColor: "#ffffff",
"input:hover ~ &": {
backgroundColor: "#f5f8fa"
},
"input:disabled ~ &": {
boxShadow: "none",
background: "rgba(206,217,224,.5)"
}
},
root: {
background: "linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)",
border: 0,
borderRadius: 3,
boxShadow: "0 3px 5px 2px rgba(255, 105, 135, .3)",
color: "white",
height: 48,
padding: "0 30px"
},
checkedIcon: {
borderRadius: 2,
"&:before": {
display: "block",
width: 24,
height: 24,
backgroundImage:
"url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Crect width='23' height='23' x='.5' y='.5' fill='%23FFF' fill-rule='nonzero' stroke='%23999' rx='4'/%3E%3Ctext fill='%23F2410A' font-size='20' font-weight='bold'%3E%3Ctspan x='1' y='18'%3E✓%3C/tspan%3E%3C/text%3E%3C/g%3E%3C/svg%3E%0A\")",
content: '""'
},
"input:hover ~ &": {
backgroundColor: "#106ba3"
}
}
});
const App = props => {
const classes = useStyles();
const [consentGiven, setConsentGiven] = useState(false);
const handleChange = event => {
!consentGiven && setConsentGiven(true);
};
return (
<div>
<Checkbox
className={classes.checkbox}
checked={consentGiven}
color="primary"
onChange={handleChange}
icon={<span className={classes.icon} />}
checkedIcon={<span className={classes.checkedIcon} />}
inputProps={{
"aria-label": "primary checkbox"
}}
/>
</div>
);
};
render(<App />, document.getElementById("root"));
index.html
:
<div id="root"></div>
Here's a Sample StackBlitz with the minimal code required to reproduce the issue.
The issue: The solution seems to work perfectly in Chrome. But in IE, once the user checks the checkbox, it disappers.
Expected Behavior: The Checkbox, once checked, should stay visible with the checked state on IE.