Skip to content

Bubble dragover and dragenter events #14

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

Merged
merged 4 commits into from
Sep 3, 2021

Conversation

Bestra
Copy link
Contributor

@Bestra Bestra commented Aug 30, 2021

What this PR does

Current direction

The implementation for https://github.com/github/github/pull/190219 needs
an event to kick off finding the cursor position, and after some discussion it makes the most sense to
bubble the dragover and dragenter events that we're currently stopping.

Originally

The implementation for https://github.com/github/github/pull/190219 needs
an event to kick off finding the cursor position, and rather than directly propagating the
DragEvent it seems prudent to fire a CustomEvent solely used by that consumer.
That'll avoid any unintended side effects in the document at large.

The implementation for github/github#190219 needs
an event to kick off finding the cursor position, and rather than bubbling the
DragEvent it seems prudent to fire a CustomEvent solely used by that consumer.
That'll avoid any unintended side effects in the document at large.
@Bestra Bestra marked this pull request as ready for review August 31, 2021 12:40
@Bestra Bestra requested a review from a team as a code owner August 31, 2021 12:40
@Bestra Bestra requested review from koddsson and manuelpuyol August 31, 2021 12:40
@Bestra
Copy link
Contributor Author

Bestra commented Aug 31, 2021

Given where the root PR is, I think this is ready for a proper look 🙇

cancelable: true,
detail: {
dragEvent: event,
attachmentElement: target
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about calling this target instead? attachmentElement made me instinctually think it was the thing being dragged, rather than the element we are dragging over

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good distinction! 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've now removed the custom event entirely 🎉

attachmentElement: target
}
})
target.dispatchEvent(dragEvent)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't check if the event was cancelled. Do we need the event to be cancellable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@koddsson that's a really good question! Even though it doesn't need to be for https://github.com/github/github/pull/190219, since this event could be used for any number of things down the road being able to preventDefault() on it and then checking if the event was cancelled might be useful. I'll set cancelable: true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, Wednesday morning 🤦. It already is cancellable. Really I could go either way. I don't think we're going to regret having it be cancellable, but in truth I don't think we'll ever need to check if it's been cancelled. Probably less is more in this case, but I'll wait to hear back.

@Bestra Bestra force-pushed the bestra/file-attachment-dragged-event branch from 2e5a30b to 25a4242 Compare September 1, 2021 13:51
@Bestra Bestra force-pushed the bestra/file-attachment-dragged-event branch from 25a4242 to 312836e Compare September 1, 2021 13:59
@Bestra
Copy link
Contributor Author

Bestra commented Sep 1, 2021

Based on an excellent question from @koddsson, I'm going to remove the custom event from this PR, and instead propagate the original dragenter or dragover events. I'll ping back when this is ready for another look.

We decided we could use the `dragover` and `dragenter` events directly
instead of wrapping them with a custom one.  We're still calling `preventDefault()`
so we won't accidentally trigger any native behavior downstream.
@Bestra Bestra changed the title Surface event for file-attachment-dragged Bubble dragover and dragenter events Sep 1, 2021
@Bestra Bestra requested a review from koddsson September 1, 2021 15:07
Copy link
Contributor

@koddsson koddsson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great!

@koddsson koddsson merged commit 5cc9107 into main Sep 3, 2021
@koddsson koddsson deleted the bestra/file-attachment-dragged-event branch September 3, 2021 11:45
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

Successfully merging this pull request may close these issues.

3 participants