@@ -15,11 +15,15 @@ title:
15
15
Custom modal content render. use `vueuse` implements draggable.
16
16
17
17
</docs >
18
-
19
18
<template >
20
19
<div >
21
20
<a-button type =" primary" @click =" showModal" >Open Modal</a-button >
22
- <a-modal ref =" modalRef" v-model:visible =" visible" @ok =" handleOk" >
21
+ <a-modal
22
+ ref =" modalRef"
23
+ v-model:visible =" visible"
24
+ :wrap-style =" { overflow: 'hidden' }"
25
+ @ok =" handleOk"
26
+ >
23
27
<p >Some contents...</p >
24
28
<p >Some contents...</p >
25
29
<p >Some contents...</p >
@@ -56,10 +60,15 @@ export default defineComponent({
56
60
const transformY = ref (0 );
57
61
const preTransformX = ref (0 );
58
62
const preTransformY = ref (0 );
63
+ const dragRect = ref ({ left: 0 , right: 0 , top: 0 , bottom: 0 });
59
64
watch ([x , y ], () => {
60
65
if (! startedDrag .value ) {
61
66
startX .value = x .value ;
62
67
startY .value = y .value ;
68
+ const bodyRect = document .body .getBoundingClientRect ();
69
+ const titleRect = modalTitleRef .value .getBoundingClientRect ();
70
+ dragRect .value .right = bodyRect .width - titleRect .width ;
71
+ dragRect .value .bottom = bodyRect .height - titleRect .height ;
63
72
preTransformX .value = transformX .value ;
64
73
preTransformY .value = transformY .value ;
65
74
}
@@ -73,8 +82,14 @@ export default defineComponent({
73
82
74
83
watchEffect (() => {
75
84
if (startedDrag .value ) {
76
- transformX .value = preTransformX .value + x .value - startX .value ;
77
- transformY .value = preTransformY .value + y .value - startY .value ;
85
+ transformX .value =
86
+ preTransformX .value +
87
+ Math .min (Math .max (dragRect .value .left , x .value ), dragRect .value .right ) -
88
+ startX .value ;
89
+ transformY .value =
90
+ preTransformY .value +
91
+ Math .min (Math .max (dragRect .value .top , y .value ), dragRect .value .bottom ) -
92
+ startY .value ;
78
93
}
79
94
});
80
95
const transformStyle = computed <CSSProperties >(() => {
0 commit comments