Skip to content

Latest commit

 

History

History
60 lines (47 loc) · 2.49 KB

README.md

File metadata and controls

60 lines (47 loc) · 2.49 KB

~700B React Click Away Listener

npm travis Coverage Status downloads/month pullrequest firsttimersonly

Installation

yarn add react-click-away-listener
  • It's quite small in size.
  • It's built with TypeScript.
  • It supports both Mouse and Touch Events.

Usage

import ClickAwayListener from 'react-click-away-listener';

const App = () => {
	const handleClickAway = () => {
		console.log('Hey, you can close the Popup now');
	};

	return (
		<div id="app">
			<ClickAwayListener onClickAway={handleClickAway}>
				<div> Some Popup, Nav or anything </div>
			</ClickAwayListener>
			<div id="rest-of-the-app">Don't name a div like that :(</div>
		</div>
	);
};

Props

Prop Default value Description
onClickAway undefined Fires when a user clicks outside the click away component
as div The rendered element type
mouseEvent click The mouse event type that gets fired on ClickAway
touchEvent touchend The touch event type that gets fired on ClickAway

Examples

LICENSE

MIT