{"id":18541464,"url":"https://github.com/kentor/react-click-outside","last_synced_at":"2025-04-12T22:31:43.851Z","repository":{"id":51776670,"uuid":"43592923","full_name":"kentor/react-click-outside","owner":"kentor","description":"Higher Order Component that provides click outside functionality","archived":false,"fork":false,"pushed_at":"2021-05-10T03:06:42.000Z","size":296,"stargazers_count":275,"open_issues_count":13,"forks_count":40,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-11T06:02:19.812Z","etag":null,"topics":["click","component","dropdown","hoc","outside","react"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kentor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-03T08:34:45.000Z","updated_at":"2024-08-16T01:40:45.000Z","dependencies_parsed_at":"2022-08-22T20:11:10.850Z","dependency_job_id":null,"html_url":"https://github.com/kentor/react-click-outside","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kentor%2Freact-click-outside","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kentor%2Freact-click-outside/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kentor%2Freact-click-outside/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kentor%2Freact-click-outside/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kentor","download_url":"https://codeload.github.com/kentor/react-click-outside/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248553676,"owners_count":21123497,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["click","component","dropdown","hoc","outside","react"],"created_at":"2024-11-06T20:05:10.080Z","updated_at":"2025-04-12T22:31:43.830Z","avatar_url":"https://github.com/kentor.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React Click Outside\n\n[![Build Status](https://travis-ci.org/kentor/react-click-outside.svg)](https://travis-ci.org/kentor/react-click-outside) [![npm](https://img.shields.io/npm/v/react-click-outside.svg)](https://www.npmjs.com/package/react-click-outside)\n\nEnhance a React component with a Higher Order Component that provides click\noutside detection.\n\n**Note:** React 0.14 required for version \u003e= 2.x. This assumes `react` and\n`react-dom` is installed in your project. Continue using version 1.x for React\n0.13 support.\n\n**Note:** Use version \u003e= 2.3.0 to get rid of `React.createClass`\nwarnings in React 15.5.\n\n## Usage\n\nInstallation:\n\n```\nnpm install react-click-outside\n```\n\nSome component that you wish to enhance with click outside detection:\n\n```js\nconst createReactClass = require('create-react-class');\nconst enhanceWithClickOutside = require('react-click-outside');\nconst React = require('react');\n\nconst Dropdown = createReactClass({\n  getInitialState() {\n    return {\n      isOpened: false,\n    };\n  },\n\n  handleClickOutside() {\n    this.toggle();\n  },\n\n  toggle() {\n    this.setState({ isOpened: !this.state.isOpened });\n  },\n\n  render() {\n    ...\n  },\n});\n\nmodule.exports = enhanceWithClickOutside(Dropdown);\n```\n\n**Note:** There will be no error thrown if `handleClickOutside` is not\nimplemented.\n\n### `wrappedRef` prop\n\nUse the `wrappedRef` prop to get access to the wrapped component instance. For\nexample:\n\n```js\n// Inside a component's render method\n\u003cDropdown\n  wrappedRef={instance =\u003e { this.toggle = instance.toggle; }}\n/\u003e\n\n// Now you can call toggle externally\nthis.toggle();\n```\n\n## Details\n\nThe `enhanceWithClickOutside` function wraps the provided component in another\ncomponent that registers a click handler on `document` for the event capturing\nphase. Using the event capturing phase prevents elements with a click handler\nthat calls `stopPropagation` from cancelling the click event that would\neventually trigger the component's `handleClickOutside` function.\n\n## Why not a mixin?\n\nThere are some mixins that provide click outside detection functionality, but\nthey prevent the component from implementing the  `componentDidMount` and\n`componentWillUnmount` life cycle hooks. I recommend not using a mixin for this\ncase.\n\n## Limitations\n\n- IE9+ due to the usage of the event capturing phase.\n\n## Not working on iOS?\n\nIf the `handleClickOutside` handler is not firing on iOS, try adding the\n`cursor: pointer` css style to the `\u003cbody\u003e` element. There are many ways to\nachieve this, here is just one example:\n\n```js\nif ('ontouchstart' in document.documentElement) {\n  document.body.style.cursor = 'pointer';\n}\n```\n\nIf your app already has a way for mobile detection (e.g. Modernizr), you may\nwant to use that instead.\n\n\nSee issue [#4][i] for a discussion.\n\n## License\n\n[MIT](LICENSE.txt)\n\n[i]: https://github.com/kentor/react-click-outside/issues/4\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkentor%2Freact-click-outside","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkentor%2Freact-click-outside","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkentor%2Freact-click-outside/lists"}