@@ -15,11 +15,15 @@ title:
1515Custom modal content render. use `vueuse` implements draggable.
1616
1717</docs >
18-
1918<template >
2019 <div >
2120 <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+ >
2327 <p >Some contents...</p >
2428 <p >Some contents...</p >
2529 <p >Some contents...</p >
@@ -56,10 +60,15 @@ export default defineComponent({
5660 const transformY = ref (0 );
5761 const preTransformX = ref (0 );
5862 const preTransformY = ref (0 );
63+ const dragRect = ref ({ left: 0 , right: 0 , top: 0 , bottom: 0 });
5964 watch ([x , y ], () => {
6065 if (! startedDrag .value ) {
6166 startX .value = x .value ;
6267 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 ;
6372 preTransformX .value = transformX .value ;
6473 preTransformY .value = transformY .value ;
6574 }
@@ -73,8 +82,14 @@ export default defineComponent({
7382
7483 watchEffect (() => {
7584 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 ;
7893 }
7994 });
8095 const transformStyle = computed <CSSProperties >(() => {
0 commit comments