1
1
import PropTypes from 'prop-types'
2
2
import React from 'react'
3
3
import { DnDContext } from './DnDContext'
4
+ import { scrollParent , scrollTop } from 'dom-helpers'
5
+ import qsa from 'dom-helpers/cjs/querySelectorAll'
4
6
5
7
import Selection , {
6
8
getBoundsForNode ,
@@ -124,13 +126,38 @@ class EventContainerWrapper extends React.Component {
124
126
} )
125
127
}
126
128
129
+ updateParentScroll = ( parent , node ) => {
130
+ setTimeout ( ( ) => {
131
+ const draggedEl = qsa ( node , '.rbc-addons-dnd-drag-preview' ) [ 0 ]
132
+ if ( draggedEl ) {
133
+ if ( draggedEl . offsetTop < parent . scrollTop ) {
134
+ scrollTop ( parent , Math . max ( draggedEl . offsetTop , 0 ) )
135
+ } else if (
136
+ draggedEl . offsetTop + draggedEl . offsetHeight >
137
+ parent . scrollTop + parent . clientHeight
138
+ ) {
139
+ scrollTop (
140
+ parent ,
141
+ Math . min (
142
+ draggedEl . offsetTop -
143
+ parent . offsetHeight +
144
+ draggedEl . offsetHeight ,
145
+ parent . scrollHeight
146
+ )
147
+ )
148
+ }
149
+ }
150
+ } )
151
+ }
152
+
127
153
_selectable = ( ) => {
128
154
let wrapper = this . ref . current
129
155
let node = wrapper . children [ 0 ]
130
156
let isBeingDragged = false
131
157
let selector = ( this . _selector = new Selection ( ( ) =>
132
158
wrapper . closest ( '.rbc-time-view' )
133
159
) )
160
+ let parent = scrollParent ( wrapper )
134
161
135
162
selector . on ( 'beforeSelect' , ( point ) => {
136
163
const { dragAndDropAction } = this . context . draggable
@@ -156,8 +183,14 @@ class EventContainerWrapper extends React.Component {
156
183
const bounds = getBoundsForNode ( node )
157
184
const { dragAndDropAction } = this . context . draggable
158
185
159
- if ( dragAndDropAction . action === 'move' ) this . handleMove ( box , bounds )
160
- if ( dragAndDropAction . action === 'resize' ) this . handleResize ( box , bounds )
186
+ if ( dragAndDropAction . action === 'move' ) {
187
+ this . updateParentScroll ( parent , node )
188
+ this . handleMove ( box , bounds )
189
+ }
190
+ if ( dragAndDropAction . action === 'resize' ) {
191
+ this . updateParentScroll ( parent , node )
192
+ this . handleResize ( box , bounds )
193
+ }
161
194
} )
162
195
163
196
selector . on ( 'dropFromOutside' , ( point ) => {
0 commit comments