Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-cool-onclickoutside

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-cool-onclickoutside

React hook to listen for clicks outside of the component(s).

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
58K
decreased by-12.19%
Maintainers
1
Weekly downloads
 
Created
Source

React Cool Onclickoutside

This is a React hook to execute callback when user clicks outside of the target component(s) area. It's a useful logic for UI interaction design (IxD) like hide a dropdown menu or tooltip etc. Hop you guys ❤️ it!

⚡️ Live demo: https://react-cool-onclickoutside.netlify.com

🚧 This package is still under development, API may changed frequently. Please don't use it now ✋🏼. The milestone as below:

  • Triggers callback when clicks outside target area
  • Uses passive touch event listener to improve scrolling performance
  • Support multiple refs
  • Clicks on the scrollbar can be ignored
  • Unit testing
  • Typescript type definition
  • Demo website
  • CI/CD
  • Documentation

Usage

General use case.

import useOnclickoutside from 'react-use-onclickoutside';

const App = () => {
  const ref = useOnclickoutside(() => {
    // Handle outside clicked...
  });

  return <div ref={ref}>{'Dropdown'}</div>;
};

Support multiple refs. Callback only be triggered when user clicks outside of both.

import useOnclickoutside from 'react-use-onclickoutside';

const App = () => {
  const ref = useOnclickoutside(() => {
    // Handle outside clicked...
  });

  return (
    <>
      <div ref={ref}>{'Dropdown 1'}</div>
      <div ref={ref}>{'Dropdown 2'}</div>
    </>
  );
};

Reference

type UseOnclickoutside = (
  callback: (event?: MouseEvent | TouchEvent) => void,
  eventTypes: string[] = ['mousedown', 'touchstart']
): (el: HTMLElement | null) => void

Keywords

FAQs

Package last updated on 07 Jan 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc