Skip to content

Commit 508b668

Browse files
fix(DND): Corrects issue of losing droppable event when releasing on non-event related containers (#2199)
#2198 #1902
1 parent b390e03 commit 508b668

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/Selection.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ const clickTolerance = 5
3838
const clickInterval = 250
3939

4040
class Selection {
41-
constructor(node, { global = false, longPressThreshold = 250 } = {}) {
41+
constructor(node, { global = false, longPressThreshold = 250, validContainers = [] } = {}) {
4242
this.isDetached = false
4343
this.container = node
4444
this.globalMouse = !node || global
4545
this.longPressThreshold = longPressThreshold
46+
this.validContainers = validContainers
4647

4748
this._listeners = Object.create(null)
4849

@@ -303,6 +304,20 @@ class Selection {
303304
}
304305
}
305306

307+
// Check whether provided event target element
308+
// - is contained within a valid container
309+
_isWithinValidContainer(e) {
310+
const eventTarget = e.target;
311+
const containers = this.validContainers;
312+
313+
if (!containers || !containers.length || !eventTarget) {
314+
return true;
315+
}
316+
317+
return containers.some(
318+
(target) => !!eventTarget.closest(target));
319+
}
320+
306321
_handleTerminatingEvent(e) {
307322
const { pageX, pageY } = getEventCoordinates(e)
308323

@@ -314,12 +329,13 @@ class Selection {
314329
if (!this._initialEventData) return
315330

316331
let inRoot = !this.container || contains(this.container(), e.target)
332+
let isWithinValidContainer = this._isWithinValidContainer(e)
317333
let bounds = this._selectRect
318334
let click = this.isClick(pageX, pageY)
319335

320336
this._initialEventData = null
321337

322-
if (e.key === 'Escape') {
338+
if (e.key === 'Escape' || !isWithinValidContainer) {
323339
return this.emit('reset')
324340
}
325341

src/addons/dragAndDrop/WeekWrapper.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ class WeekWrapper extends React.Component {
152152
let node = this.ref.current.closest('.rbc-month-row, .rbc-allday-cell')
153153
let container = node.closest('.rbc-month-view, .rbc-time-view')
154154

155-
let selector = (this._selector = new Selection(() => container))
155+
let selector = (
156+
this._selector = new Selection(
157+
() => container,
158+
{ validContainers: ['.rbc-day-slot', '.rbc-allday-cell'] }
159+
))
156160

157161
selector.on('beforeSelect', (point) => {
158162
const { isAllDay } = this.props

0 commit comments

Comments
 (0)