Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@material/react-ripple

material-components21.2kMIT0.15.0TypeScript support: included

Material Components React Ripple

mdc web react, material components react, material design, ripple

readme

React Ripple

A React version of an MDC Ripple.

Installation

npm install @material/react-ripple

Usage

Styles

with Sass:

import '@material/react-ripple/index.scss';

You'll also need to include these sass mixins on the element. Please also refer to Advanced Sass Mixins to customize further.

@import "@material/ripple/mdc-ripple.scss";

// refer to element in Javascript portion below
.ripple-icon-component {
  @include mdc-ripple-surface;
  @include mdc-ripple-radius-bounded;
  @include mdc-states;
  overflow: hidden;
}

with CSS:

import '@material/react-ripple/dist/ripple.css';

Javascript Instantiation

To wrap a component with the ripple HOC, please follow this example:

import {withRipple} from '@material/react-ripple';

const Icon = (props) => {
  const {
    children,
    className = '',
    // You must call `initRipple` from the root element's ref. This attaches the ripple
    // to the element.
    initRipple,
    // include `unbounded` to remove warnings when passing `otherProps` to the
    // root element.
    unbounded,
    ...otherProps
  } = props;

  // any classes needed on your component needs to be merged with
  // `className` passed from `props`.
  const classes = `ripple-icon-component ${className}`;

  return (
    <div
      className={classes}
      ref={initRipple}
      {...otherProps}>
      {children}
    </div>
  );
};

const RippleIcon = withRipple(Icon);

Wrap your Icon component with the HOC withRipple, which returns a component with a ripple capable surface.

Typescript

If you're using TS, you will need to extend from the provided InjectedProps.


import {withRipple, InjectedProps} from '@material/react-ripple';

interface IconProps extends InjectedProps<HTMLDivElement> {
  children?: React.ReactNode;
  className: string;
  initRipple: React.Ref<HTMLDivElement>;
  unbounded: boolean;
}

const Icon = (props) => {
  const {
    children,
    className = '',
    // You must call `initRipple` from the root element's ref. This attaches the ripple
    // to the element.
    initRipple,
    // include `unbounded` to remove warnings when passing `otherProps` to the
    // root element.
    unbounded,
    ...otherProps
  } = props;

  // any classes needed on your component needs to be merged with
  // `className` passed from `props`.
  const classes = `ripple-icon-component ${className}`;

  return (
    <div
      className={classes}
      ref={initRipple}
      {...otherProps}>
      {children}
    </div>
  );
};

const RippleIcon = withRipple<IconProps, HTMLDivElement>(Icon);

Advanced Usage

Ripple surface and ripple activator

You may want to apply the visual treatment (CSS classes and styles) for a ripple surface on one element, but have its activation rely on a different element. For example, putting a ripple on a <div> which will be activated by focusing on a child <input> element. We call the visual element the "ripple surface" and the activating element the "ripple activator".

The initRipple callback prop can take in an extra activator argument for the case where the ripple activator differs from the ripple surface. If the activator argument is not provided, the ripple surface will also serve as the ripple activator.

import {withRipple} from '@material/react-ripple';

const MyInput = (props) => {
  const {
    rippleActivator,
    ...otherProps
  } = props;

  return (
    <input ref={rippleActivator} {...otherProps} />
  );
}

class MyComponent extends React.Component {
  rippleActivator = React.createRef();

  init = (el) => {
    this.props.initRipple(el /* surface */, this.rippleActivator.current /* activator */);
  }

  render() {
    const {
      className,
      initRipple,
      unbounded,
      ...otherProps
    } = this.props;

    return (
      <div
        className={`my-component ${className}`}
        ref={this.init}
        {...otherProps}>
        <MyInput rippleActivator={this.rippleActivator} />
      </div>
    );
  }
};

const MyRippledComponent = withRipple(MyComponent);

Props

Prop Name Type Description
unbounded boolean Ripple is unbounded if true.
disabled n/a Disables ripple if true.
style object Inline styles of root element.
className string Classes to appear on className attribute of root element.

Sass Mixins

Sass mixins may be available to customize various aspects of the components. Please refer to the MDC Web repository for more information on what mixins are available, and how to use them.

Advanced Sass Mixins

changelog

0.15.0 (2019-07-22)

Bug Fixes

  • infrastructure: chips need unique key (#974) (58408c8)
  • infrastructure: add eslint ignore lines (#973) (7172019)
  • list: Only apply aria-orientation with role (#945) (beab319)
  • list: Remove selected & activated from prop spread (#977) (4f36078)
  • ripple: broken relative imports (#953) (aabe0c1)

Features

  • list: Implement getAttributeForElementIndex (#948) (00f2ef1)

BREAKING CHANGES

  • list: 'orientation` is now used instead of 'aria-orientation' to specify list orientation. This allows smarter aria defaults that can be overridden if needed.

0.14.1 (2019-07-02)

Bug Fixes

  • infrastructure: fix SSR support for webpack4 update (#956) (5d3a89d)

0.14.0 (2019-06-25)

Bug Fixes

  • master on travis.yml (#922) (407de75)
  • infrastructure: update docker command to run new image (#923) (10a68f6)
  • npm vulnerabilities (#903) (92a1840)
  • switch react to peerDependency for all packages (#940) (cc06add)
  • ripple: focus style alive when disabled (#943) (e222e94)
  • ripple: not activating when clicked after touch (#932) (b2f7855)
  • text-field: label isn't float when set value with setState (#934) (f829e12)

chore

Features

  • infrastructure: add typescript production typings test (#900) (1f7f872)
  • select: add 'form' attribute to NativeControl component (#907) (044117f)
  • tab: Allow to render Tab as an anchor node (#928) (5108e76)
  • text-field: add placeholder property (#930) (0818061)

BREAKING CHANGES

  • text-field: handleValueChange is removed from Input's props.
  • top-app-bar: Top App Bar render props removed

0.13.2 (2019-06-11)

Bug Fixes

  • list: update checkbox and radio deps (#919) (685b23b)

0.13.0 (2019-05-30)

Bug Fixes

  • chips: ClientRect/DOMRect is not IE11 compatible (#855) (88697da)
  • chips: error with undefined or null children (#883) (d733c29)
  • chips, text-field: add null check for foundation (#675) (#870) (40ca635)
  • select: className option is passed to select and overrides selectClassName (#872) (6e2aac1)
  • select: componentDidUpdate handles disabled prop change (#877) (db7f0ce)
  • select: edit * imports (#874) (33eb962)

Features

0.12.1 (2019-05-08)

Bug Fixes

  • fab: Made initRipple and unbounded props optional (#854) (baca67b)
  • infrastructure: fix postinstall (#842) (5077078)

Features

  • button: define CSS_CLASSES (#838) (cbf6cc5)
  • text-field: Sync inputComponent when component is updated (#848) (2b954fa )

0.12.0 (2019-05-01)

Bug Fixes

  • list make listitem props optional (#766) (ffd7776)
  • top-app-bar change scrollTop to offsetTop in getViewportScrollY ( (#832) (a207b0d)
  • Ensure all package.json files have a link to the repo (#807) (10f2614)
  • Remove MDCTextfield Constant External (#803) (2269920)

Features

BREAKING CHANGES

  • Text-field, select, list have API changes. Please see PR #830 for more details.

0.11.0 (2019-03-19)

Bug Fixes

Features

0.10.0 (2019-02-19)

Bug Fixes

  • button: Support anchor and button HTML attributes (#679) (#680) (be8790e)
  • checkbox: enable name attribute (#678) (2c77ab5)
  • chips: ChipSet no longer overwrites handle[Interaction|Select|Re… (#651) (e0b0946)
  • chips: copy selectedChipIds before calling setState (#645) (37905d3)
  • chips: id shuold be required prop (#649) (afc16c8)
  • infrastructure: fix source mappings under dist directory (#682) (9f93ef3)
  • infrastructure: Upgrade resemblejs to v3 (#634) (53abeac)
  • infrastructure: Windows development (#662) (fbc4b26)
  • list: renders a list with children which is not DOM (#674) (e66a267)
  • ripple: Ripple triggers twice on mobile (#646) (6876e62)
  • tab: return ScrollContentWidth (#633) (c4a2a01)
  • text-field: Do not import constants from @material/textfield internals (#639) (3b3a0ab)
  • top-app-bar: clientHeight unit test (#668) (9c7330b)

Features

  • chips: implements missing adapter method notifyTrailingIconInteraction (#653) (c5e87a6)
  • fab: exited (#661) (a646a33)
  • infrastructure: Fix screenshot tests for external contributors and pull requests (#638) (3d421b1)
  • snackbar: new component (#620) (63e1fce)

BREAKING CHANGES

  • chips: renamed chip.props.removeIcon --> chips.props.trailingIcon

0.9.3 (2019-02-14)

Bug Fixes

0.9.2 (2019-01-30)

0.9.1 (2019-01-30)

0.9.0 (2019-01-23)

Bug Fixes

  • list: Support null as a child element for ListItem (#584) (bf487d7)
  • ripple: add missing dependency to package.json (#612) (f6e4725)
  • ripple: Adds HTMLElement shim to fix regression for SSR projects (#592) (3aaf871)
  • text field: adds missing adapter method notifyIconAction on Icon (#600) (632896a)
  • top-app-bar: make top app bar props optional (#587) (1585c95)

Features

0.8.0 (2018-12-28)

Bug Fixes

  • infrastructure: add declaration package.json (#572) (8cb4b1b)
  • infrastructure: condense webpack configuration build step into one json file (#571) (512f3aa)
  • infrastructure: unit test code coverage for typescript (#487) (1170a1f)
  • list: minification-safe element type comparison (#509) (89f5fd2)
  • select: defensive foundation check before unmounting - also includes radio, checkbox, text-field (#512) (2ee4c80)
  • top-app-bar: foundation should be destroyed and reinitialized on variant change (#519) (58cfc6f)
  • lint for typings files (#577) (8f971a8)
  • remove prop-types from package.json (#576) (7f38952)

Features

BREAKING CHANGES

  • infrastructure: Remove <package-name>.es.js files. The alternate is now to use the index.tsx files.
  • ripple: withRipple is no longer the default export.

0.7.1 (2018-11-30)

Bug Fixes

  • added missing comma from golden.json (#426) (dfe44dc)
  • chips: update to v0.41.0 (#424) (e40fec6)
  • drawer: initialize foundation if props.open updates (#427) (36e6316)
  • drawer: replace focus trap with vanilla version (#437) (bd7433b)
  • drawer: update modal screenshot golden (#482) (ce0c314)
  • linear-progress: Add linear progress (#450) (f38d575)
  • select: added check for nativeControl element before calling props.setRippleCenter in NativeControl (#478) (5baad76)
  • tab-bar: set previousActiveIndex to props.activeIndex initially to avoid tab of undefined error (#428) (8e28944)
  • text-field: custom validation (#430) (f5c9c35)
  • text-field: uncomment test fixed from 0.35.0 (#404) (3a908ff)

Features

0.6.2 (2018-11-07)

Bug Fixes

  • checkbox: add focusable=false to svg for a11y (#375) (c7f3b97)
  • drawer: update readme and screenshots to support below top app bar (#397) (90adbbe)
  • infrastructure: increase screenshot timeout to decrease flakes (#373) (e96ca10)
  • layout-grid: remove unit test console warnings (#379) (408cdd2)
  • list: selectedIndex 0 isn't working (#387) (4e62aae)
  • text-field: added reference to input element (#414) (ea04dc6)
  • text-field: allow for input isValid override (#374) (7872856)
  • text-field: put foundation on state and do render input unless foundation is present (#353) (2cb5d64)
  • text-field: remove foundation.setValue call during onChange (#350) (36469f7)
  • top-app-bar: add FixedAdjust to npmignore (#371) (d4ad675)
  • top-app-bar: allow react elements in title (#376) (f6da361)

Code Refactoring

Features

  • infrastructure: add verify pkg main to dist script (#320) (459c6dd)

BREAKING CHANGES

  • list: Event handlers moved from list to list item. New props on list item for focus, follow href, toggle checkbox, and classnames/attributes passed down from list. Remove ID prop from list item.

0.6.0 (2018-10-24)

Bug Fixes

  • chips: added npmignore (#317) (ac99ac5)
  • chips: replace relative path with npm package (#297) (93ac25e)
  • icon-button: add main field to package.json (#300) (88d5e4e)
  • icon-button: add MIT license to files (#313) (97ecb3a)
  • icon-button: update main property (#319) (e79995d)
  • infrastructure: add more time to screenshot initial wait (#314) (375206e)
  • infrastructure: fix travis badge on readme (#331) (e637782)
  • infrastructure: speed up prerelease script (#288) (b77819f)
  • menu-surface: fix menu surface unit test typo (#315) (8b60622)
  • text-field: Add support for <textarea> (#118) (#266) (d9cff89)
  • text-field: floating label width calculation when notched (#347) (377f250)
  • top-app-bar: add fixed adjust component (#349) (f1d4be0)

Features

0.5.1 (2018-09-25)

Bug Fixes

  • line-ripple: stop calling foundation.setRippleCenter when argument is NaN (#287) (4bbc4fa)

0.5.0 (2018-09-25)

Bug Fixes

  • card: add missing hasRipple (#248) (#255) (d2f58d6)
  • chips: add chip leading icon class management (#281) (c638e79)
  • chips: remove handleRemove method for chipsUpdate method (#282) (8435079)
  • chips: use notifyRemoval and notifyInteraction adapter methods (#277) (ba433ea)
  • infrastructure: add the es5 @material/package/dist/mdc.package to externals (#223) (73fb45b)
  • ripple: react-ripple does not contain styles (#172) (#251) (ac0f87f)
  • tab: update readme and ref name in tab component (#226) (f18fda1)
  • tab-bar: add missing url from screenshot list (#264) (dd2f183)
  • tab-bar: Arrow keys should focus adjacent tab (#280) (54224c8)
  • tab-indicator: update component to work with mdc tab (#215) (bc41a8b)
  • tab indicator sliding animation broken (#273) (c436f58)

Features

BREAKING CHANGES

  • chips: Updated API for selectedChipIds and handleSelect props in ChipSet and id prop in Chip.

0.4.2 (2018-08-14)

0.4.1 (2018-08-13)

Bug Fixes

  • infrastructure: point all tests to es6 files for accurate test coverage (#198) (4959266)
  • ripple: add test to avoid computeBoundingRect error (#200) (769b15b)
  • screenshot increase timeout (#210) (e9a2089)
  • text-field: add missing prop style (#184) (ff9704d)
  • text-field: fix typo in readme (#197) (f88f180)
  • text-field: update isRtl to a prop (#195) (cd7c7c8)

Features

BREAKING CHANGES

  • text-field: In order for rtl to work on the Notched Outline component, isRtl will need to be passed in as boolean (default is false). Updating isRtl will result in a re-render.

0.4.0 (2018-07-30)

Bug Fixes

  • infrastructure: updated deploy steps to run with docker (#116) (a53fc7d)
  • downgraded to es2015 preset to work on ie11 (#133) (05c0184)
  • material-icon: removed blocking line and updated documentation (#155) (8f3cef5)
  • ripple: setState warning when unmounting the component (#112) (841a1c8)
  • text-field: move handleValueChange call when this.props.value updates (#170) (f46a34d)
  • top-app-bar: add material icon imports in screenshot tests (#168) (526400b)
  • point packages to MDC Web /dist ES5 files (#182) (9d387d3)

Chores

  • fab: Pass icon as a prop, not a child element (#159) (1569f97)

Features

  • button: Add an href prop to use anchor tag instead of button (#174) (0df9967)
  • chips: Add new component (#117) (410da30)
  • chips: Add selection to chips (#121) (3ef1123)
  • ripple: Call focus/blur handlers from foundation (#135) (c438333)

BREAKING CHANGES

  • fab: Please update your FAB to pass icon as a prop, not as a child element.
  • chips: Users should render Chip components directly instead of passing a labels prop to ChipSet.

0.3.0 (2018-06-25)

Bug Fixes

  • Moved importer code to webpack.util to share between screen shot test and main build. (aec8cc8)
  • travis and docker integration (#92) (e7f4497)
  • updated function name and tests (7c2794d)
  • line-ripple: Convert style name to camel case (#99) (2a5341c)
  • text-field: Added SASS importer to lookup the package folder first then fallback to default npm resolve. (bf7f849)
  • text-field: Added text-field to valid commit msg list (3922e2c)
  • text-field: Updated Input.js to use new public API of foundation (df0b5ed)

Features

  • Docker integration into Travis to decrease false negative screenshots (#91) (d8b670e)
  • updated all packages to 0.36.0 (#104) (a1d8b66)
  • infrastructure: add .npmignores to packages (#110) (ab7009d)
  • infrastructure: default npm entry point to ES5 (#108) (1f0446f)

0.2.0 (2018-06-01)

Bug Fixes

  • Remove scss extensions from @material/mdc-* imports (#62) (46b7f08)
  • button: Rename stroked to outlined (#74) (f612388)
  • infrastructure: fixed npm run build error for empty package directories (#85) (18666d4)
  • infrastructure: Make all components public (#43) (27a1ab1)
  • ripple: Trigger on key events (2248f26)

Features

0.1.0 (2018-05-09)

Bug Fixes

  • button: Update package.json (507298e)
  • card: Update package.json (fc7a4dd)
  • fab: Update package.json (efd4703)
  • floating-label: Update package.json (92cbf2c)
  • line-ripple: Update package.json (b6fc89c)
  • material-icon: Update package.json (18e2508)
  • notched-outline: Update package.json (8b18779)
  • ripple: Update package.json (044c308)
  • text-field: Update package.json (fda82fb)
  • top-app-bar: Update package.json (06e9d66)

Features

  • remote hosted screenshot testing (#12) (98bcdfe)
  • screenshot testing (#10) (5fd6d86)
  • fab: Add new tests for svg/img (1f536b7)
  • fab: Change node to element. (2b4960e)
  • fab: Remove empty fab from test. Add waitUntil idle to wait until the stylesheets finish (43e58d4)
  • fab: Update class name (96c2d61)
  • fab: Update for comments (9b041d6)
  • fab: Update for comments (676ae32)
  • fab: Update for lint (3748f31)
  • fab: Update package name (02b7140)