From 3a6ac628c93070167d3e3c3903a593bc1de05928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E8=BE=BE=E5=BB=BA?= Date: Thu, 29 Aug 2024 16:05:06 +0800 Subject: [PATCH] fix(Popover): popover ref.current.show() invalid --- src/components/popover/popover.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/popover/popover.tsx b/src/components/popover/popover.tsx index c0e27e76dc..664013663c 100644 --- a/src/components/popover/popover.tsx +++ b/src/components/popover/popover.tsx @@ -79,13 +79,17 @@ export const Popover = forwardRef((p, ref) => { useImperativeHandle( ref, () => ({ - show: () => setVisible(true), + show: () => { + stateRef.current.isClickShow = true + setVisible(true) + }, hide: () => setVisible(false), visible, }), [visible] ) + const stateRef = useRef({ isClickShow: false }) const targetRef = useRef(null) const floatingRef = useRef(null) const arrowRef = useRef(null) @@ -196,6 +200,10 @@ export const Popover = forwardRef((p, ref) => { useClickAway( () => { if (!props.trigger) return + if (stateRef.current.isClickShow) { + stateRef.current.isClickShow = false + return + } setVisible(false) }, [() => targetRef.current?.element, floatingRef],