Skip to content

Commit

Permalink
fix(Popover): Popover ref.current.show() invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
吴达建 committed Aug 29, 2024
1 parent 7e6f7e6 commit be64c17
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/components/popover/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,17 @@ export const Popover = forwardRef<PopoverRef, PopoverProps>((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<Wrapper>(null)
const floatingRef = useRef<HTMLDivElement>(null)
const arrowRef = useRef<HTMLDivElement>(null)
Expand Down Expand Up @@ -196,6 +200,10 @@ export const Popover = forwardRef<PopoverRef, PopoverProps>((p, ref) => {
useClickAway(
() => {
if (!props.trigger) return
if (stateRef.current.isClickShow) {
stateRef.current.isClickShow = false;
return;
}
setVisible(false)
},
[() => targetRef.current?.element, floatingRef],
Expand Down

0 comments on commit be64c17

Please sign in to comment.