@@ -5,7 +5,6 @@ import { isUndefined } from 'lodash-es';
55import log from '@tdesign/common-js/log/index' ;
66import { pxCompat } from '@tdesign/common-js/utils/helper' ;
77
8- import { canUseDocument } from '../_util/dom' ;
98import Portal from '../common/Portal' ;
109import useAttach from '../hooks/useAttach' ;
1110import useConfig from '../hooks/useConfig' ;
@@ -23,28 +22,6 @@ import useLockStyle from './hooks/useLockStyle';
2322import type { StyledProps } from '../common' ;
2423import type { DialogInstance , TdDialogProps } from './type' ;
2524
26- type MousePosition = { x : number ; y : number } | null ;
27-
28- let mousePosition : MousePosition ;
29-
30- const getClickPosition = ( e : MouseEvent ) => {
31- mousePosition = {
32- x : e . pageX ,
33- y : e . pageY ,
34- } ;
35- // 100ms 内发生过点击事件,则从点击位置动画展示
36- // 否则直接 zoom 展示
37- // 这样可以兼容非点击方式展开
38- setTimeout ( ( ) => {
39- mousePosition = null ;
40- } , 100 ) ;
41- } ;
42-
43- // 只有点击事件支持从鼠标位置动画展开
44- if ( canUseDocument ) {
45- document . documentElement . addEventListener ( 'click' , getClickPosition , true ) ;
46- }
47-
4825export interface DialogProps extends TdDialogProps , StyledProps {
4926 isPlugin ?: boolean ; // 是否以插件形式调用
5027}
@@ -103,12 +80,11 @@ const Dialog = forwardRef<DialogInstance, DialogProps>((originalProps, ref) => {
10380 const isFullScreen = mode === 'full-screen' ;
10481
10582 const dialogAttach = useAttach ( 'dialog' , attach ) ;
106- const [ animationVisible , setAnimationVisible ] = useState ( visible ) ;
10783 const [ dialogAnimationVisible , setDialogAnimationVisible ] = useState ( false ) ;
10884
109- const { focusTopDialog } = useDialogEsc ( visible , wrapRef ) ;
11085 useLockStyle ( { preventScrollThrough, visible, mode, showInAttachedElement } ) ;
111- useDialogPosition ( visible , dialogCardRef ) ;
86+ const { activateDialog } = useDialogEsc ( visible , wrapRef ) ;
87+ const { applyTransform } = useDialogPosition ( dialogCardRef ) ;
11288 const { isInputInteracting } = useDialogDrag ( {
11389 dialogCardRef,
11490 canDraggable : ! isFullScreen && draggable ,
@@ -121,15 +97,14 @@ const Dialog = forwardRef<DialogInstance, DialogProps>((originalProps, ref) => {
12197 } , [ props , setState ] ) ;
12298
12399 useEffect ( ( ) => {
124- if ( dialogAnimationVisible ) {
125- wrapRef . current ?. focus ( ) ;
126- if ( mousePosition && dialogCardRef . current ) {
127- const offsetX = mousePosition . x - dialogCardRef . current . offsetLeft ;
128- const offsetY = mousePosition . y - dialogCardRef . current . offsetTop ;
100+ if ( ! dialogCardRef . current ) return ;
101+ dialogCardRef . current . style . display = dialogAnimationVisible ? 'block' : 'none' ;
129102
130- dialogCardRef . current . style . transformOrigin = `${ offsetX } px ${ offsetY } px` ;
131- }
103+ if ( dialogAnimationVisible ) {
104+ activateDialog ( ) ;
105+ applyTransform ( ) ;
132106 }
107+ // eslint-disable-next-line react-hooks/exhaustive-deps
133108 } , [ dialogAnimationVisible ] ) ;
134109
135110 useImperativeHandle ( ref , ( ) => ( {
@@ -200,30 +175,23 @@ const Dialog = forwardRef<DialogInstance, DialogProps>((originalProps, ref) => {
200175 // Portal Animation
201176 const onAnimateStart = ( ) => {
202177 onBeforeOpen ?.( ) ;
203- setAnimationVisible ( true ) ;
204178 if ( ! wrapRef . current ) return ;
205179 wrapRef . current . style . display = 'block' ;
206180 } ;
207181
208182 const onAnimateLeave = ( ) => {
209183 onClosed ?.( ) ;
210- setAnimationVisible ( false ) ;
211- focusTopDialog ( ) ;
212184 if ( ! wrapRef . current ) return ;
213185 wrapRef . current . style . display = 'none' ;
214186 } ;
215187
216188 // Dialog Animation
217189 const onInnerAnimateStart = ( ) => {
218190 setDialogAnimationVisible ( true ) ;
219- if ( ! dialogCardRef . current ) return ;
220- dialogCardRef . current . style . display = 'block' ;
221191 } ;
222192
223193 const onInnerAnimateLeave = ( ) => {
224194 setDialogAnimationVisible ( false ) ;
225- if ( ! dialogCardRef . current ) return ;
226- dialogCardRef . current . style . display = 'none' ;
227195 } ;
228196
229197 const renderMask = ( ) => {
@@ -265,7 +233,7 @@ const Dialog = forwardRef<DialogInstance, DialogProps>((originalProps, ref) => {
265233 [ `${ componentCls } __ctx--absolute` ] : showInAttachedElement ,
266234 [ `${ componentCls } __ctx--modeless` ] : isModeless ,
267235 } ) }
268- style = { { zIndex, display : animationVisible ? undefined : 'none' } }
236+ style = { { zIndex } }
269237 onKeyDown = { handleKeyDown }
270238 tabIndex = { 0 }
271239 >
0 commit comments