A React component for dealing with clicks outside its subtree
Last updated 10 months ago by ljharb .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install react-outside-click-handler 
SYNC missed versions from official npm registry.


A React component for handling outside clicks


import OutsideClickHandler from 'react-outside-click-handler';

function MyComponent() {
  return (
      onOutsideClick={() => {
        alert('You clicked outside of this component!!!');
      Hello World


children: PropTypes.node.isRequired

Since the OutsideClickHandler specifically handles clicks outside a specific subtree, children is expected to be defined. A consumer should also not render the OutsideClickHandler in the case that children are not defined.

Note that if you use a Portal (native or react-portal) of any sort in the children, the OutsideClickHandler will not behave as expected.

onOutsideClick: PropTypes.func.isRequired

The onOutsideClick prop is also required as without it, the OutsideClickHandler is basically a heavy-weight <div />. It takes the relevant clickevent as an arg and gets triggered when the user clicks anywhere outside of the subtree generated by the DOM node.

disabled: PropTypes.bool

If the disabled prop is true, outside clicks will not be registered. This can be utilized to temporarily disable interaction without unmounting/remounting the entire tree.

useCapture: PropTypes.bool

See for more information on event bubbling vs. capture.

If useCapture is true, the event will be registered in the capturing phase and thus, propagated top-down instead of bottom-up as is the default.

display: PropTypes.oneOf(['block', 'flex', 'inline-block', 'inline', 'contents'])

By default, the OutsideClickHandler renders a display: block <div /> to wrap the subtree defined by children. If desired, the display can be set to inline-block, inline, flex, or contents instead. There is no way not to render a wrapping <div />.

Current Tags

  • 1.3.0                                ...           latest (10 months ago)

10 Versions

  • 1.3.0                                ...           10 months ago
  • 1.2.4                                ...           a year ago
  • 1.2.3                                ...           a year ago
  • 1.2.2                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
  • 0.3.0                                ...           2 years ago
  • 0.2.0                                ...           2 years ago
  • 0.1.0                                ...           3 years ago
Today 73
This Week 345
This Month 382
Last Day 84
Last Week 1,127
Last Month 2,851
Dependencies (5)
Dev Dependencies (25)
Dependents (128)

Copyright 2014 - 2016 © |