fix duplicated click event for wrapped checkbox

This commit is contained in:
myl7
2021-11-27 19:04:21 +08:00
parent 66edd3034f
commit e706051238
+9 -3
View File
@@ -4,7 +4,7 @@ import emojiRegex from 'emoji-regex'
import { useClipboard } from 'use-clipboard-copy'
import { ParsedUrlQuery } from 'querystring'
import { FunctionComponent, useEffect, useRef, useState } from 'react'
import { FunctionComponent, MouseEventHandler, useEffect, useRef, useState } from 'react'
import { ImageDecorator } from 'react-viewer/lib/ViewerProps'
import { useRouter } from 'next/router'
@@ -111,8 +111,14 @@ const Checkbox: FunctionComponent<{
}
}
}, [ref, checked, indeterminate])
const handleClick = () => {
if (ref.current) ref.current.click()
const handleClick: MouseEventHandler = (e) => {
if (ref.current) {
if (e.target === ref.current) {
e.stopPropagation()
} else {
ref.current.click()
}
}
}
return (