From 679e974122bfca7e8128eb89666ec6f663236a40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B9=A4=E4=BB=99?= Date: Tue, 10 Dec 2024 17:12:39 +0800 Subject: [PATCH] fix(Popover): autoUpdate not working when defaultVisible is false --- src/components/popover/popover.tsx | 48 +++++++++++++++--------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/components/popover/popover.tsx b/src/components/popover/popover.tsx index c0e27e76dc..719a74154f 100644 --- a/src/components/popover/popover.tsx +++ b/src/components/popover/popover.tsx @@ -1,40 +1,40 @@ +import { + arrow, + autoUpdate, + computePosition, + flip, + hide, + limitShift, + offset, + shift, +} from '@floating-ui/dom' +import { useClickAway, useIsomorphicLayoutEffect } from 'ahooks' +import classNames from 'classnames' +import type { ReactElement, ReactNode } from 'react' import React, { forwardRef, + useEffect, useImperativeHandle, useRef, useState, - useEffect, } from 'react' -import type { ReactNode, ReactElement } from 'react' -import classNames from 'classnames' +import { convertPx } from '../../utils/convert-px' +import { NativeProps, withNativeProps } from '../../utils/native-props' +import { + GetContainer, + renderToContainer, +} from '../../utils/render-to-container' +import { useShouldRender } from '../../utils/should-render' import { usePropsValue } from '../../utils/use-props-value' import { mergeProps } from '../../utils/with-default-props' -import { NativeProps, withNativeProps } from '../../utils/native-props' import { PropagationEvent, withStopPropagation, } from '../../utils/with-stop-propagation' import { Arrow } from './arrow' -import { - GetContainer, - renderToContainer, -} from '../../utils/render-to-container' -import { - arrow, - computePosition, - flip, - offset, - autoUpdate, - hide, - shift, - limitShift, -} from '@floating-ui/dom' -import { Wrapper } from './wrapper' -import { useShouldRender } from '../../utils/should-render' -import { useClickAway, useIsomorphicLayoutEffect } from 'ahooks' import { DeprecatedPlacement, Placement } from './index' import { normalizePlacement } from './normalize-placement' -import { convertPx } from '../../utils/convert-px' +import { Wrapper } from './wrapper' const classPrefix = `adm-popover` @@ -187,11 +187,11 @@ export const Popover = forwardRef((p, ref) => { useEffect(() => { const floatingElement = floatingRef.current - if (!targetElement || !floatingElement) return + if (!targetElement || !floatingElement || !visible) return return autoUpdate(targetElement, floatingElement, update, { elementResize: typeof ResizeObserver !== 'undefined', }) - }, [targetElement]) + }, [targetElement, visible]) useClickAway( () => {