@@ -3,7 +3,7 @@ import { useEffect, useId, useRef } from 'react';
33import ReactDOM from 'react-dom' ;
44import { filter } from 'rxjs' ;
55
6- import { useAsync , useElement , useEventCallback , usePrefixConfig , useUpdatePosition } from '../../hooks' ;
6+ import { useAsync , useElement , useEventCallback , useLayout , usePrefixConfig } from '../../hooks' ;
77
88export interface DPopupPopupRenderProps {
99 'data-popup-popupid' : string ;
@@ -50,6 +50,7 @@ export function DPopup(props: DPopupProps): JSX.Element | null {
5050
5151 //#region Context
5252 const dPrefix = usePrefixConfig ( ) ;
53+ const { dScrollEl, dResizeEl } = useLayout ( ) ;
5354 //#endregion
5455
5556 const dataRef = useRef < {
@@ -60,19 +61,21 @@ export function DPopup(props: DPopupProps): JSX.Element | null {
6061
6162 const uniqueId = useId ( ) ;
6263
63- const containerEl = useElement (
64- isUndefined ( dContainer )
65- ? ( ) => {
66- let el = document . getElementById ( `${ dPrefix } popup-root` ) ;
67- if ( ! el ) {
68- el = document . createElement ( 'div' ) ;
69- el . id = `${ dPrefix } popup-root` ;
70- document . body . appendChild ( el ) ;
71- }
72- return el ;
73- }
74- : dContainer
75- ) ;
64+ const scrollEl = useElement ( dScrollEl ) ;
65+ const resizeEl = useElement ( dResizeEl ) ;
66+ const containerEl = useElement ( ( ) => {
67+ if ( isUndefined ( dContainer ) ) {
68+ let el = document . getElementById ( `${ dPrefix } popup-root` ) ;
69+ if ( ! el ) {
70+ el = document . createElement ( 'div' ) ;
71+ el . id = `${ dPrefix } popup-root` ;
72+ document . body . appendChild ( el ) ;
73+ }
74+ return el ;
75+ }
76+
77+ return dContainer ;
78+ } ) ;
7679
7780 const changeVisible = ( visible ?: boolean ) => {
7881 if ( isUndefined ( visible ) ) {
@@ -127,7 +130,7 @@ export function DPopup(props: DPopupProps): JSX.Element | null {
127130 asyncCapture . deleteGroup ( asyncId ) ;
128131 } ;
129132 }
130- } , [ asyncCapture , handleTrigger , dTrigger , dVisible , dDisabled ] ) ;
133+ } , [ asyncCapture , dDisabled , dTrigger , dVisible , handleTrigger ] ) ;
131134
132135 useEffect ( ( ) => {
133136 if ( ! dDisabled && dVisible && dEscClosable ) {
@@ -146,11 +149,7 @@ export function DPopup(props: DPopupProps): JSX.Element | null {
146149 asyncCapture . deleteGroup ( asyncId ) ;
147150 } ;
148151 }
149- } , [ asyncCapture , handleTrigger , dEscClosable , dVisible , dDisabled ] ) ;
150-
151- useUpdatePosition ( ( ) => {
152- dUpdatePosition ?.( ) ;
153- } , ! dDisabled && dVisible ) ;
152+ } , [ asyncCapture , dDisabled , dEscClosable , dVisible , handleTrigger ] ) ;
154153
155154 useEffect ( ( ) => {
156155 if ( ! dDisabled && dVisible ) {
@@ -174,8 +173,7 @@ export function DPopup(props: DPopupProps): JSX.Element | null {
174173 asyncCapture . deleteGroup ( asyncId ) ;
175174 } ;
176175 }
177- // eslint-disable-next-line react-hooks/exhaustive-deps
178- } , [ asyncCapture , dVisible , uniqueId , dDisabled ] ) ;
176+ } , [ asyncCapture , dDisabled , dUpdatePosition , dVisible , uniqueId ] ) ;
179177
180178 useEffect ( ( ) => {
181179 if ( ! dDisabled && dVisible && dContainer ) {
@@ -195,8 +193,37 @@ export function DPopup(props: DPopupProps): JSX.Element | null {
195193 asyncCapture . deleteGroup ( asyncId ) ;
196194 } ;
197195 }
198- // eslint-disable-next-line react-hooks/exhaustive-deps
199- } , [ asyncCapture , dContainer , dDisabled , dVisible ] ) ;
196+ } , [ asyncCapture , dContainer , dDisabled , dUpdatePosition , dVisible ] ) ;
197+
198+ useEffect ( ( ) => {
199+ if ( ! dDisabled && dVisible && scrollEl ) {
200+ const [ asyncGroup , asyncId ] = asyncCapture . createGroup ( ) ;
201+
202+ asyncGroup . fromEvent ( scrollEl , 'scroll' , { passive : true } ) . subscribe ( {
203+ next : ( ) => {
204+ dUpdatePosition ?.( ) ;
205+ } ,
206+ } ) ;
207+
208+ return ( ) => {
209+ asyncCapture . deleteGroup ( asyncId ) ;
210+ } ;
211+ }
212+ } , [ asyncCapture , dDisabled , dUpdatePosition , dVisible , scrollEl ] ) ;
213+
214+ useEffect ( ( ) => {
215+ if ( ! dDisabled && dVisible && resizeEl ) {
216+ const [ asyncGroup , asyncId ] = asyncCapture . createGroup ( ) ;
217+
218+ asyncGroup . onResize ( resizeEl , ( ) => {
219+ dUpdatePosition ?.( ) ;
220+ } ) ;
221+
222+ return ( ) => {
223+ asyncCapture . deleteGroup ( asyncId ) ;
224+ } ;
225+ }
226+ } , [ asyncCapture , dDisabled , dUpdatePosition , dVisible , resizeEl ] ) ;
200227
201228 const childProps : DPopupRenderProps = { 'data-popup-triggerid' : uniqueId } ;
202229 if ( ! dDisabled ) {
0 commit comments