mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
Fixing clickOutside
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { forwardRef, useEffect, Ref, MouseEvent } from 'react'
|
||||
import React, { useRef, useEffect, MouseEvent } from 'react'
|
||||
import hasParent from './has-parent'
|
||||
|
||||
interface ClickOutsideProps {
|
||||
@@ -7,18 +7,12 @@ interface ClickOutsideProps {
|
||||
children: any
|
||||
}
|
||||
|
||||
const ClickOutside = forwardRef(
|
||||
(
|
||||
{ active = true, onClick, children }: ClickOutsideProps,
|
||||
ref: Ref<HTMLDivElement> | null | any = {}
|
||||
) => {
|
||||
const innerRef = ref?.current
|
||||
const ClickOutside = ({ active = true, onClick, children }: ClickOutsideProps) => {
|
||||
const innerRef = useRef()
|
||||
|
||||
const handleClick = (event: any) => {
|
||||
if (!hasParent(event.target, innerRef)) {
|
||||
if (!hasParent(event.target, innerRef?.current)) {
|
||||
if (typeof onClick === 'function') {
|
||||
event.preventDefault()
|
||||
event.stopImmediatePropagation()
|
||||
onClick(event)
|
||||
}
|
||||
}
|
||||
@@ -38,8 +32,7 @@ const ClickOutside = forwardRef(
|
||||
}
|
||||
})
|
||||
|
||||
return React.cloneElement(children, { ref })
|
||||
return React.cloneElement(children, { ref: innerRef })
|
||||
}
|
||||
)
|
||||
|
||||
export default ClickOutside
|
||||
|
Reference in New Issue
Block a user