I am trying to create a custom click effect for the MUI Button by removing the default ripple effect and implementing my own shadow effect. I have disabled the ripple using disableRipple, but I am facing issues in applying the shadow effect when the user clicks on the button.
import * as React from "react";
import Button from "@mui/material/Button";
import { alpha } from "@mui/material/styles";
export default function DefaultProps() {
return (
<Button
variant="outlined"
// className='Mui-focusVisible'
disableRipple
sx={{
"&:hover": {
boxShadow: `0px 0px 0px 0px ${alpha("#000", 0.16)}`
},
"&.Mui-focusVisible": {
boxShadow: `0px 0px 0px 50px ${alpha("#000", 0.16)}`
},
"&.Mui-active": {
boxShadow: `0px 0px 0px 8px ${alpha("#000", 0.16)}`
}
}}
>
Change default props
</Button>
);
}
I have referred to the Mui-focusVisible class to add shadow on click as mentioned in the documentation.
disableRipple bool false
If true, the ripple effect is disabled. ⚠️ Without a ripple there is no styling for :focus-visible by default. Be sure to highlight the element by applying separate styles with the .Mui-focusVisible class.
I am aiming to achieve a click effect similar to the one used in Ant Design buttons. You can see the Ant Design buttons for reference here.
Code Sandbox link for the demo: https://codesandbox.io/s/defaultprops-material-demo-forked-rhggn?file=/demo.js
If anyone can help me with this, I would greatly appreciate it.