Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
react-click-outside
Advanced tools
Enhance a React component with a Higher Order Component that provides click outside detection.
Note: React 0.14 required for version >= 2.x. This assumes react
and
react-dom
is installed in your project. Continue using version 1.x for React
0.13 support.
Note: Use version >= 2.3.0 to get rid of React.createClass
warnings in React 15.5.
Installation:
npm install react-click-outside
Some component that you wish to enhance with click outside detection:
const createReactClass = require('create-react-class');
const enhanceWithClickOutside = require('react-click-outside');
const React = require('react');
const Dropdown = createReactClass({
getInitialState() {
return {
isOpened: false,
};
},
handleClickOutside() {
this.toggle();
},
toggle() {
this.setState({ isOpened: !this.state.isOpened });
},
render() {
...
},
});
module.exports = enhanceWithClickOutside(Dropdown);
Note: There will be no error thrown if handleClickOutside
is not
implemented.
wrappedRef
propUse the wrappedRef
prop to get access to the wrapped component instance. For
example:
// Inside a component's render method
<Dropdown
wrappedRef={instance => { this.toggle = instance.toggle; }}
/>
// Now you can call toggle externally
this.toggle();
The enhanceWithClickOutside
function wraps the provided component in another
component that registers a click handler on document
for the event capturing
phase. Using the event capturing phase prevents elements with a click handler
that calls stopPropagation
from cancelling the click event that would
eventually trigger the component's handleClickOutside
function.
There are some mixins that provide click outside detection functionality, but
they prevent the component from implementing the componentDidMount
and
componentWillUnmount
life cycle hooks. I recommend not using a mixin for this
case.
If the handleClickOutside
handler is not firing on iOS, try adding the
cursor: pointer
css style to the <body>
element. There are many ways to
achieve this, here is just one example:
if ('ontouchstart' in document.documentElement) {
document.body.style.cursor = 'pointer';
}
If your app already has a way for mobile detection (e.g. Modernizr), you may want to use that instead.
See issue #4 for a discussion.
FAQs
A component wrapper that provides click outside detection.
The npm package react-click-outside receives a total of 48,358 weekly downloads. As such, react-click-outside popularity was classified as popular.
We found that react-click-outside demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.