Skip to content

Commit

Permalink
fix: calendar auto scroll while dragging event at top/bottom edge (#2230
Browse files Browse the repository at this point in the history
)

Closes #2231
  • Loading branch information
AmitRDesai authored Feb 14, 2023
1 parent 0918777 commit d1c5085
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/addons/dragAndDrop/EventContainerWrapper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import PropTypes from 'prop-types'
import React from 'react'
import { DnDContext } from './DnDContext'
import { scrollParent, scrollTop } from 'dom-helpers'
import qsa from 'dom-helpers/cjs/querySelectorAll'

import Selection, {
getBoundsForNode,
Expand Down Expand Up @@ -124,13 +126,38 @@ class EventContainerWrapper extends React.Component {
})
}

updateParentScroll = (parent, node) => {
setTimeout(() => {
const draggedEl = qsa(node, '.rbc-addons-dnd-drag-preview')[0]
if (draggedEl) {
if (draggedEl.offsetTop < parent.scrollTop) {
scrollTop(parent, Math.max(draggedEl.offsetTop, 0))
} else if (
draggedEl.offsetTop + draggedEl.offsetHeight >
parent.scrollTop + parent.clientHeight
) {
scrollTop(
parent,
Math.min(
draggedEl.offsetTop -
parent.offsetHeight +
draggedEl.offsetHeight,
parent.scrollHeight
)
)
}
}
})
}

_selectable = () => {
let wrapper = this.ref.current
let node = wrapper.children[0]
let isBeingDragged = false
let selector = (this._selector = new Selection(() =>
wrapper.closest('.rbc-time-view')
))
let parent = scrollParent(wrapper)

selector.on('beforeSelect', (point) => {
const { dragAndDropAction } = this.context.draggable
Expand All @@ -156,8 +183,14 @@ class EventContainerWrapper extends React.Component {
const bounds = getBoundsForNode(node)
const { dragAndDropAction } = this.context.draggable

if (dragAndDropAction.action === 'move') this.handleMove(box, bounds)
if (dragAndDropAction.action === 'resize') this.handleResize(box, bounds)
if (dragAndDropAction.action === 'move') {
this.updateParentScroll(parent, node)
this.handleMove(box, bounds)
}
if (dragAndDropAction.action === 'resize') {
this.updateParentScroll(parent, node)
this.handleResize(box, bounds)
}
})

selector.on('dropFromOutside', (point) => {
Expand Down

0 comments on commit d1c5085

Please sign in to comment.