Tiny React Click Away Listener built with React Hooks
MIT License
Bot releases are hidden (Show)
Published by ooade over 2 years ago
This is to ensure that the onClickAway
handler is fired whenever we focus on another element outside of the ClickAway component.
Thanks to @rishabh-ink for sending a PR for this! π
Published by ooade over 3 years ago
In this version, we no longer create an element and listen to the click and touchdown events whenever it's being triggered from anywhere on the document body excluding the element created.
Now, the event listener is being attached to the children with cloneElement
, and we ensured not to replace the children's ref, onClick
event and onTouchEnd
events while doing that.
Note: It will only break your existing app if you depend on the previous Clickaway component for styling or if you have other properties on the listener. But you if previously rendered it as a span and the only property added is onClickAway
, you can upgrade to the new version.
Shoutout to @jblevins1991 for suggesting this flow.
Published by ooade over 3 years ago
Published by ooade over 3 years ago
This version makes it possible to use Clickaway listener with React Portals! π
Published by ooade about 4 years ago
This allows users to pass an "as" property to the click away listener and have it rendered as such.
Thanks to @calebdeji for this! π
Published by ooade over 4 years ago
Just a few updates:
S/O to @Alphy11 for this release π
Published by ooade over 4 years ago
Passing the event in the callback ensures that you could make use of the event as you could do on every event handlers.
It makes it possible to do stuff like event.preventDefault()
and all.
Thanks to @Naismith for bringing it up and implementing! π
Published by ooade over 4 years ago
Yeah, it's live. We now support:
Breaking change as we switched from using mouseDown
to click
as the default mouse event.