-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
TL;DR:
Is Event's originalEvent property something I can use? Should it be added to the docs to reflect that?
Is your feature request related to a problem? Please describe.
I need to detect when a given Sortable item has been dragged out of the Sortable container element into a FullCalendar calendar on my page. This is so I can cancel reordering and other Sortable functionality that may have happened if an item was dragged out of a Sortable list and onto my calendar.
It should behave like below. Note: The reorder instantly goes away and something is inserted into the calendar when I drop on the calendar.
Describe the solution you'd like
My solution right now looks like the following. I simply use contains to see if the evt.originalEvent.target is outside my Sortable list container (that is, see if we dropped somewhere else, e.g. the calendar).
onEnd: (evt) => {
if (evt.oldIndex !== evt.newIndex) {
// ...
// ... Redacted proprietary code ...
// ...
if (this.element.contains((evt as any).originalEvent.target)) { // 👈 The line most relevant to this issue
// Make move happen (call backend to make the change "stick," etc). We dropped it somewhere within the Sortable container.
} else {
// Cancel the move. We dropped it somewhere outside of the `Sortable` container.
}
}
}But originalEvent is not part of the documented, public API for Event so I'm reluctant to take a dependency on it for fear it may change or stop working in the future.
Is there a reason not to add originalEvent to the documentation for Event? And make it a bonafide, stable public API? Is there something wrong with my solution above that maybe I'm not considering?
I noticed the code assigning the originalEvent property is some of the oldest in this repo so it seems stable. 😁
If we did make this change, I wonder if we would want to deprecate the second parameter in onMove's current signature which is function (/**Event*/evt, /**Event*/originalEvent) { since originalEvent is accessible on evt.originalEvent.
Describe alternatives you've considered
- Use FullCalendar's API to invoke some custom function which cancels the Sortable drag. That's significantly more complex and couples the two APIs together rather tightly.
- Undo the reordering that happens immediately when the dragged item leaves the Sortable container
- This is a better interaction design IMHO and is actually preferred. But I couldn't figure out a straightforward way to make this happen with Sortable's API. I would love a recommendation on a straightforward way to make this happen.
Additional context
To be clear, getting FullCalendar to accept drops from Sortable list items is not the concern. I already have that working. The unsolved problem is conditionally disabling Sortable behavior.
