Yes, you can use TouchRipple
to emulate the ripple effect. This component is undocumented, but you can see how it's used in the ButtonBase
and learn to use it yourself.
First, you need to pass a ref to TouchRipple
and call ref.current.start(e)
or ref.current.stop(e)
when you want to start or stop the effect respectively.
e
is the event object. When you call start(e)
, it needs the mouse or touch position (from mousedown
or touchstart
event) to know where to start the ripple effect (Source). You can override this behavior by setting center
props to true
, which makes the ripple effect always start at the middle.
Below is the minimum working example to get you started:
function App() {
const rippleRef = React.useRef(null);
const onRippleStart = (e) => {
rippleRef.current.start(e);
};
const onRippleStop = (e) => {
rippleRef.current.stop(e);
};
return (
<div
onMouseDown={onRippleStart}
onMouseUp={onRippleStop}
style={{
display: "inline-block",
padding: 8,
position: "relative",
border: "black solid 1px"
}}
>
Button
<TouchRipple ref={rippleRef} center={false} />
</div>
);
}
Live Demo
TouchRipple
component uses adiv
, so there's no problem in using it to wrap abutton
element. – Infatuate