Skip to content

vlazh/react-outside-click-listener

Repository files navigation

Outside click listener for React

npm package

Installation

npm install --save react-outside-click-listener
# or
yarn add react-outside-click-listener

Usage example

import { OutsideClickListener } from 'react-outside-click-listener';

function MyComponent() {
  return (
    <OutsideClickListener
      disabled={condition} // Disable by some condition
      ignore=".css-class" // CSS selector for ignored elements.
      events={['mousedown', 'touchstart']} // Events which detects as clicks. Default value.
      onOutsideClick={callback}
    >
      {/* Child must hold a ref to dom node. */}
      <Child />
    </OutsideClickListener>
  );
}