Skip to content

Commit

Permalink
Merge pull request #6795 from ant-design/popover-dynamic
Browse files Browse the repository at this point in the history
fix(Popover): autoUpdate not working when defaultVisible is false
  • Loading branch information
guoyunhe authored Dec 14, 2024
2 parents 495be63 + 679e974 commit 8407aae
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions src/components/popover/popover.tsx
Original file line number Diff line number Diff line change
@@ -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`

Expand Down Expand Up @@ -187,11 +187,11 @@ export const Popover = forwardRef<PopoverRef, PopoverProps>((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(
() => {
Expand Down

0 comments on commit 8407aae

Please sign in to comment.