Skip to content

Latest commit

 

History

History
35 lines (23 loc) · 895 Bytes

OutsideClick.md

File metadata and controls

35 lines (23 loc) · 895 Bytes

<OutsideClick>

Tracks clicks outside its children or clickRoots().

Usage

Default

import {OutsideClick} from 'libreact/lib/OutsideClick';

<OutsideClick onClick={}>
  <div>Don't click here.</div>
</OutsideClick>

Using a Portal

import {OutsideClick} from 'libreact/lib/OutsideClick';

<OutsideClick onClick={} clickRoots={() => ([
  document.getElementById('my-portal-root')
])}>
  <div>Click anywhere outside `#my-portal-root` and my `onClick` will fire.</div>
</OutsideClick>

Props

  • onClick — event called when user click outside of its children.
  • event — optional, string, event name subscribe to, defaults to mousedown.
  • clickRoots — optional, function that should return an array of DOM nodes. These should be considered where the user clicks inside, i.e. clicking outside of these roots will fire onClick.