@@ -2,12 +2,18 @@ import Portal from '@rc-component/portal';
22import { clsx } from 'clsx' ;
33import type { CSSMotionProps } from '@rc-component/motion' ;
44import { useResizeObserver } from '@rc-component/resize-observer' ;
5- import { getDOM , isDOM } from '@rc-component/util/lib/Dom/findDOMNode' ;
6- import { getShadowRoot } from '@rc-component/util/lib/Dom/shadow' ;
7- import { getNodeRef , useComposeRef } from '@rc-component/util/lib/ref' ;
8- import useEvent from '@rc-component/util/lib/hooks/useEvent' ;
9- import useId from '@rc-component/util/lib/hooks/useId' ;
10- import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect' ;
5+ import {
6+ getDOM ,
7+ getNodeRef ,
8+ getShadowRoot ,
9+ isDOM ,
10+ supportRef ,
11+ useComposeRef ,
12+ useControlledState ,
13+ useEvent ,
14+ useId ,
15+ useLayoutEffect ,
16+ } from '@rc-component/util' ;
1117import * as React from 'react' ;
1218import Popup , { type MobileConfig } from './Popup' ;
1319import type { TriggerContextProps } from './context' ;
@@ -22,6 +28,7 @@ import type { PortalProps } from '@rc-component/portal';
2228import type {
2329 ActionType ,
2430 AlignType ,
31+ AnimationType ,
2532 ArrowPos ,
2633 ArrowTypeOuter ,
2734 BuildInPlacements ,
@@ -31,12 +38,12 @@ import { getAlignPopupClassName } from './util';
3138export type {
3239 ActionType ,
3340 AlignType ,
41+ AnimationType ,
3442 ArrowTypeOuter as ArrowType ,
3543 BuildInPlacements ,
3644} ;
3745
3846import UniqueProvider , { type UniqueProviderProps } from './UniqueProvider' ;
39- import { useControlledState } from '@rc-component/util' ;
4047import { flushSync } from 'react-dom' ;
4148
4249export { UniqueProvider } ;
@@ -791,13 +798,17 @@ export function generateTrigger(
791798 useResizeObserver ( mergedOpen , targetEle , onTargetResize ) ;
792799
793800 // Compose refs
794- const mergedRef = useComposeRef ( setTargetRef , getNodeRef ( child ) ) ;
801+ const childSupportRef = supportRef ( child ) ;
802+ const mergedRef = useComposeRef (
803+ setTargetRef ,
804+ childSupportRef ? getNodeRef ( child ) : null ,
805+ ) ;
795806
796807 // Child Node
797808 const triggerNode = React . cloneElement ( child , {
798809 ...mergedChildrenProps ,
799810 ...passedProps ,
800- ref : mergedRef ,
811+ ref : childSupportRef ? mergedRef : undefined ,
801812 } ) ;
802813
803814 // Render
@@ -869,4 +880,36 @@ export function generateTrigger(
869880 return Trigger ;
870881}
871882
883+ interface MockPortalProps {
884+ open ?: boolean ;
885+ autoDestroy ?: boolean ;
886+ children : React . ReactElement < any > ;
887+ getContainer ?: ( ) => HTMLElement ;
888+ }
889+
890+ const MockPortal : React . FC < MockPortalProps > = ( {
891+ open,
892+ autoDestroy,
893+ children,
894+ getContainer,
895+ } ) => {
896+ const [ visible , setVisible ] = React . useState ( open ) ;
897+
898+ React . useEffect ( ( ) => {
899+ getContainer ?.( ) ;
900+ } ) ;
901+
902+ React . useEffect ( ( ) => {
903+ if ( open ) {
904+ setVisible ( true ) ;
905+ } else if ( autoDestroy ) {
906+ setVisible ( false ) ;
907+ }
908+ } , [ open , autoDestroy ] ) ;
909+
910+ return visible ? children : null ;
911+ } ;
912+
913+ export const MockTrigger = generateTrigger ( MockPortal ) ;
914+
872915export default generateTrigger ( Portal ) ;
0 commit comments