@diana-ui/hooks
Advanced tools
Comparing version 0.1.3 to 0.1.4
/// <reference types="react" /> | ||
declare function useOnClickOutside(ref: React.RefObject<HTMLElement | undefined>, onClickOutside: (target: HTMLElement) => void): void; | ||
declare function useOnClickOutside(refs: React.RefObject<HTMLElement | undefined>[], onClickOutside: (target: HTMLElement) => void): void; | ||
export default useOnClickOutside; |
import { useEffect } from "react"; | ||
function useOnClickOutside(ref, onClickOutside) { | ||
function useOnClickOutside(refs, onClickOutside) { | ||
var handleClickOutside = function (event) { | ||
var target = event.target; | ||
if (ref.current && !ref.current.contains(target)) { | ||
var hasClickedOutside = refs.every(function (ref) { return ref.current && !ref.current.contains(target); }); | ||
if (hasClickedOutside) { | ||
onClickOutside(target); | ||
@@ -7,0 +8,0 @@ } |
/// <reference types="react" /> | ||
declare function useOnClickOutside(ref: React.RefObject<HTMLElement | undefined>, onClickOutside: (target: HTMLElement) => void): void; | ||
declare function useOnClickOutside(refs: React.RefObject<HTMLElement | undefined>[], onClickOutside: (target: HTMLElement) => void): void; | ||
export default useOnClickOutside; |
import { useEffect } from "react"; | ||
function useOnClickOutside(ref, onClickOutside) { | ||
function useOnClickOutside(refs, onClickOutside) { | ||
const handleClickOutside = (event) => { | ||
const target = event.target; | ||
if (ref.current && !ref.current.contains(target)) { | ||
const hasClickedOutside = refs.every(ref => ref.current && !ref.current.contains(target)); | ||
if (hasClickedOutside) { | ||
onClickOutside(target); | ||
@@ -7,0 +8,0 @@ } |
{ | ||
"name": "@diana-ui/hooks", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"main": "lib/index.js", | ||
@@ -28,3 +28,3 @@ "module": "module/index.js", | ||
}, | ||
"gitHead": "e86821d8818d20611bf9af2238d579a411983821" | ||
"gitHead": "7ef8c57f0220085ac2a07f7f97dfcfb7f665460f" | ||
} |
6325
126