Plus · DragMove
DragMove
Set elements to change their position by dragging
When to use
It is used to set the element that can be dragged to change its position. It supports limiting the drag range and customizing the elements that trigger dragging.
Demos
How to introduce
DragMove supported from v2.71.0.
Basic usage
Elements wrapped by
DragMove
will be able to change their position by dragging.Notice
- DragMove will set the draggable element to absolute positioning
- DragMove needs to apply DOM event listeners to children. If the child element is a custom component, you need to ensure that it can pass properties to the underlying DOM element. The following types of children are supported:
- Class Component, it is not mandatory to bind ref, but you need to ensure that props can be transparently transmitted to the real DOM node
- Use the functional component wrapped by forwardRef to transparently transmit props and ref to the real DOM node in children
- Real DOM nodes, such as span, div, p...
Limit drag range
Passing in
constrainer
, this function returns the elements that limit the draggable range.Note: The elements returned by the constrainer need to be positioned relative
Customize elements that trigger dragging
Passing in
handler
, this function returns the element that triggered the drag. If not set, you can click anywhere to drag; if set, only the part of the element returned by the handler can be dragged.Customize position processing after dragging
You can customize the position processing after dragging through
customMove
. After this parameter is set, the DragMove component will only return the calculated position through the parameters without setting it. The user can set the new position as needed.API
Property | Description | Type | Default value |
---|---|---|---|
allowInputDrag | Whether to allow dragging when clicking on native input/textarea | boolean | false |
allowMove | Determine whether dragging is allowed when clicking/touching. | (event: TouchEvent |MouseEvent, element: ReactNode) => boolean | - |
constrainer | Returns the element that limits the draggable range. | () => ReactNode | 'parent' | - |
customMove | Customize position processing after dragging | (element: ReactNode, top: number, left: number) => void | - |
handler | Returns the element that triggers dragging. | () => ReactNode | - |
onMouseDown | Callback when mouse is pressed | (e: MouseEvent) => void | - |
onMouseMove | Callback when mouse moves | (e: MouseEvent) => void | - |
onMouseUp | Callback when mouse is raised | (e: MouseEvent) => void | - |
onTouchCancel | Callback when touch cancels | (e: TouchEvent) => void | - |
onTouchEnd | callback when touch ends | (e: TouchEvent) => void | - |
onTouchMove | Callback when touch moves | (e: TouchEvent) => void | - |
onTouchStart | Callback when touch starts | (e: TouchEvent) => void | - |