1.3.0 • Published 5 years ago

react-outside-click-handler v1.3.0

Weekly downloads
503,167
License
MIT
Repository
github
Last release
5 years ago

react-outside-click-handler

A React component for handling outside clicks

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 />.

@procore/labs-workflowsreact-datapicker-jalaalielevenia-ui-framework@pil0t/gatsby-theme-novela@thirdwave-network/thirdwave-gatsby-themetheme-brandfetch@snapboard/gridpwa-feleaf-react-datesscreencloud-app-error-components@kyrelldixon/gatsby-theme-novelajalali-support-react-datesmewdavellircustom-gatsby-theme-novelawocorakuten-rampagetalent-app-shellnuxxx_componentsnuxxxcomponents@luxrobo/entry-toolairbnb-react-dates@rakuten-rampage/rampagepylot-framework4game-uiblinkreceipt-grouping-tool-clientopenknowl-eungwang-libraryaliens-design-system-frontplugin-table-oc@slid/interactive-product-system@infinitebrahmanuniverse/nolb-react-o@pixiebrix/extension@everything-registry/sub-chunk-2601@skillx/react-dates@unicorn1984/mkui-bsa-nice-bloggo-theme@vzhangdev/fta_cash_management@vtex/styleguide@vertrax/vertrax-ui@varld/fontless-components@utfsrb-ui-kit/components@utfsrb-ui-kit/core@zahradnik-io/gatsby-theme-novela@vapor/components@super0605/squareark-ui-sdkbasikit@crpt-ui/datatable@dasa-health/components-react@dasa-health/alma-react@cthsiao/gatsby-theme-novela-mod@cscenter/react-dates@availity/react-datesestimize-react-dateseureka-designeureka-design2clientview_banking@hyype-inc/widgetcontentoo-componentsemidates@heroku/react-hk-componentscarbery-uielevenia-ui@holism/components@holism/core@alec.brunelle/gatsby-theme-novela@ambler/andive@bricksandbraces/designsystem@davidway/gatsby-theme-novela@jayswain/react-datesgo1d-deploy-test@jlongster/gatsby-theme-novelafno-buy-formgrey-vest@newstackdev/iosdk@newcoin-foundation/iosdkhc-inbox-chat-comphc-inbox-conversationhc-inbox-conversations@newlantern/ohif-ui@mohsen_saremi/react-datesgsi-ui@myfan/web-componentsh-react-dates@mycelium-ethereum/vyps-kitgatsby-theme-projectagatsby-theme-puristdates-responsive-s4gatsby-theme-operetta@legend620/ohif-uiflight-search-calendar@launchpadlab/lp-components@clifmo/gatsby-theme-novela@contexture/react@draftbox-co/gatsby-ghost-novela-theme@draftbox-co/gatsby-wordpress-novela-themeblog-themeblt-react-dates@draekien/clean-ui@getzeroday/gatsby-theme-novela@frontegg/react-devdru
1.3.0

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

7 years ago