diff --git a/src/packages/drag/__test__/__snapshots__/drag.spec.tsx.snap b/src/packages/drag/__test__/__snapshots__/drag.spec.tsx.snap index e39f5dfd9d..c84ad9cc8c 100644 --- a/src/packages/drag/__test__/__snapshots__/drag.spec.tsx.snap +++ b/src/packages/drag/__test__/__snapshots__/drag.spec.tsx.snap @@ -11,6 +11,7 @@ exports[`Drag > should render default slot correctly 1`] = ` exports[`Drag > touch move 1`] = `
{ return ( <>
-
+

{translated.basic}

diff --git a/src/packages/drag/demos/taro/demo1.tsx b/src/packages/drag/demos/taro/demo1.tsx index 956bac39ff..dfc7b69728 100644 --- a/src/packages/drag/demos/taro/demo1.tsx +++ b/src/packages/drag/demos/taro/demo1.tsx @@ -3,7 +3,7 @@ import { Drag, Button } from '@nutui/nutui-react-taro' const Demo1 = () => { return ( - + ) diff --git a/src/packages/drag/demos/taro/demo2.tsx b/src/packages/drag/demos/taro/demo2.tsx index 959b2f3ccd..f46256820a 100644 --- a/src/packages/drag/demos/taro/demo2.tsx +++ b/src/packages/drag/demos/taro/demo2.tsx @@ -10,6 +10,7 @@ const Demo2 = () => { top: '200px', left: '8px', }} + className="drag-demo21" > @@ -19,6 +20,7 @@ const Demo2 = () => { top: '200px', right: '50px', }} + className="drag-demo22" > diff --git a/src/packages/drag/demos/taro/demo3.tsx b/src/packages/drag/demos/taro/demo3.tsx index 1beaf5a852..87be2fbfa4 100644 --- a/src/packages/drag/demos/taro/demo3.tsx +++ b/src/packages/drag/demos/taro/demo3.tsx @@ -10,6 +10,7 @@ const Demo3 = () => { top: '275px', left: '0px', }} + className="drag-demo3" > diff --git a/src/packages/drag/demos/taro/demo4.tsx b/src/packages/drag/demos/taro/demo4.tsx index 2d5df941c1..7ac2923b44 100644 --- a/src/packages/drag/demos/taro/demo4.tsx +++ b/src/packages/drag/demos/taro/demo4.tsx @@ -27,6 +27,7 @@ const Demo4 = () => { }} /> diff --git a/src/packages/drag/drag.scss b/src/packages/drag/drag.scss index 4875abc705..ec167762d3 100644 --- a/src/packages/drag/drag.scss +++ b/src/packages/drag/drag.scss @@ -1,10 +1,14 @@ .nut-drag { position: fixed; - display: inline-flex; z-index: 9997 !important; - width: fit-content; - height: fit-content; + width: 0; + height: 0; touch-action: none; user-select: none; font-size: 0; + &-inner { + display: inline-flex; + width: fit-content; + height: fit-content; + } } diff --git a/src/packages/drag/drag.taro.tsx b/src/packages/drag/drag.taro.tsx index 2242714b11..a3f97afb4f 100644 --- a/src/packages/drag/drag.taro.tsx +++ b/src/packages/drag/drag.taro.tsx @@ -1,6 +1,7 @@ import React, { FunctionComponent, useState, useEffect, useRef } from 'react' import { getSystemInfoSync, createSelectorQuery } from '@tarojs/taro' import { BasicComponent, ComponentDefaults } from '@/utils/typings' +import { getRectByTaro } from '@/utils/get-rect-by-taro' export interface DragProps extends BasicComponent { attract: boolean @@ -45,20 +46,22 @@ export const Drag: FunctionComponent< const translateY = useRef(0) const middleLine = useRef(0) - const getInfo = () => { + const getInfo = async () => { const el = myDrag.current if (el) { const { top, left, bottom, right } = boundary const { screenWidth, windowHeight } = getSystemInfoSync() + const { width, height } = await getRectByTaro(dragRef.current) + dragRef.current?.getBoundingClientRect() createSelectorQuery() .select(`.${className}`) .boundingClientRect((rec: any) => { setBoundaryState({ top: -rec.top + top, left: -rec.left + left, - bottom: windowHeight - rec.height - rec.top - bottom, - right: screenWidth - rec.width - rec.left - right, + bottom: windowHeight - rec.top - bottom - Math.ceil(height), + right: screenWidth - rec.left - right - Math.ceil(width), }) middleLine.current = @@ -135,6 +138,7 @@ export const Drag: FunctionComponent< ref={myDrag} >
touchStart(event)} ref={dragRef} onTouchMove={touchMove} diff --git a/src/packages/drag/drag.tsx b/src/packages/drag/drag.tsx index fc2155fa49..cb76fdd9b7 100644 --- a/src/packages/drag/drag.tsx +++ b/src/packages/drag/drag.tsx @@ -45,7 +45,10 @@ export const Drag: FunctionComponent< const getInfo = () => { const el = myDrag.current if (el) { - const { offsetWidth, offsetHeight, offsetTop, offsetLeft } = el + const { offsetTop, offsetLeft } = el + const { offsetWidth, offsetHeight } = el.querySelector( + `.${classPrefix}-inner` + ) as HTMLDivElement const { clientWidth, clientHeight } = document.documentElement const { top, left, bottom, right } = boundary setBoundaryState({ @@ -94,7 +97,11 @@ export const Drag: FunctionComponent< {...reset} ref={myDrag} > - + {children}