Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add ripple effect when clicking Card in MUI

Tags:

Is there a way I can add ripple effect to MUI Card component on click.

And I would also like to know, is it possible to make ripple effect to come on top of the content of Card component, rather that it showing as background.

like image 538
Vishal Vijay Avatar asked Feb 23 '16 15:02

Vishal Vijay


People also ask

What is ripple effect in MUI?

Ripple. MDC Ripple provides the JavaScript and CSS required to provide components (or any element at all) with a material "ink ripple" interaction effect. It is designed to be efficient, uninvasive, and usable without adding any extra DOM to your elements.

What causes a ripple effect?

A ripple effect occurs when an initial disturbance to a system propagates outward to disturb an increasingly larger portion of the system, like ripples expanding across the water when an object is dropped into it.

What is ripple effect on button?

Ripple touch effect was introduced with material design in Android 5.0 (API level 21). Touch feedback in material design provides an instantaneous visual confirmation at the point of contact when users interact fwith UI elements.

What is Disableripple material UI?

According to Material-UI documentation, you can disable the ripple effect globally by providing the following in your theme: import React from "react"; import Button from "@material-ui/core/Button"; import { createMuiTheme, MuiThemeProvider } from "@material-ui/core"; export default function ContainedButtons() { const ...


1 Answers

I noticed that TouchRipple has been moved out of the internal directory. It's now available in the ButtonBase folder.

Here is how I was able to add ripple effect by using the ButtonBase component -

Basically, you wrap your component, let's say <Card> inside the <ButtonBase> like so, and the ButtonBase takes care of the TouchRipple setting up for you -

<ButtonBase>      <Card>          ....      </Card> </ButtonBase> 

Here is a Codesandbox link to working demo. I know this is not the best way. You could directly use the TouchRipple/Ripple component, but I found this way to be very easy to use.

Hope this helps.

like image 193
Gryk Avatar answered Oct 14 '22 08:10

Gryk