From e706051238423701e38df85dccfb12dc3864e255 Mon Sep 17 00:00:00 2001 From: myl7 Date: Sat, 27 Nov 2021 19:04:21 +0800 Subject: [PATCH] fix duplicated click event for wrapped checkbox --- components/FileListing.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/components/FileListing.tsx b/components/FileListing.tsx index c401bc3..b224e23 100644 --- a/components/FileListing.tsx +++ b/components/FileListing.tsx @@ -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 (