react-outside-click-handler

WebJar for react-outside-click-handler

License

License

MIT
Categories

Categories

IDE Development Tools React User Interface Web Frameworks CLI
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

react-outside-click-handler
Last Version

Last Version

1.3.0
Release Date

Release Date

Type

Type

jar
Description

Description

react-outside-click-handler
WebJar for react-outside-click-handler
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/airbnb/react-outside-click-handler

Download react-outside-click-handler

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/react-outside-click-handler/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>react-outside-click-handler</artifactId>
    <version>1.3.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/react-outside-click-handler/
implementation 'org.webjars.npm:react-outside-click-handler:1.3.0'
// https://jarcasting.com/artifacts/org.webjars.npm/react-outside-click-handler/
implementation ("org.webjars.npm:react-outside-click-handler:1.3.0")
'org.webjars.npm:react-outside-click-handler:jar:1.3.0'
<dependency org="org.webjars.npm" name="react-outside-click-handler" rev="1.3.0">
  <artifact name="react-outside-click-handler" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='react-outside-click-handler', version='1.3.0')
)
libraryDependencies += "org.webjars.npm" % "react-outside-click-handler" % "1.3.0"
[org.webjars.npm/react-outside-click-handler "1.3.0"]

Dependencies

compile (5)

Group / Artifact Type Version
org.webjars.npm : consolidated-events jar [1.1.1,2),[2.0.0,3)
org.webjars.npm : document.contains jar [1.0.1,2)
org.webjars.npm : airbnb-prop-types jar [2.15.0,3)
org.webjars.npm : object.values jar [1.1.0,2)
org.webjars.npm : prop-types jar [15.7.2,16)

Project Modules

There are no modules declared in this project.

react-outside-click-handler

A React component for handling outside clicks

Installation

$ npm install react-outside-click-handler

Usage

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

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

Props

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 https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#Event_bubbling_and_capture 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 />.

org.webjars.npm

Airbnb

Versions

Version
1.3.0
1.2.2