Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Add originalEvent to Event's documented, public API #2392

Open
PatrickNausha opened this issue Jul 16, 2024 · 0 comments
Open

[feature] Add originalEvent to Event's documented, public API #2392

PatrickNausha opened this issue Jul 16, 2024 · 0 comments

Comments

@PatrickNausha
Copy link

PatrickNausha commented Jul 16, 2024

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.

drag-disable

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant