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

Provide reasonable fallback for event target when mouse position exits viewport #19

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/src/draggable_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ abstract class _EventManager {
startSubs.clear();
}

/// Determine a target using `document.elementFromPoint` via the provided [clientPosition].
///
/// Falls back to `document.body` if no element is found at the provided [clientPosition].
EventTarget _getRealTargetFromPoint(Point clientPosition) {
return document.elementFromPoint(clientPosition.x, clientPosition.y) ?? document.body;
}

/// Determine the actual target that should receive the event because
/// mouse or touch event might have occurred on a drag avatar.
///
Expand All @@ -130,7 +137,7 @@ abstract class _EventManager {
EventTarget _getRealTarget(Point clientPosition, {EventTarget target}) {
// If no target was provided get it.
if (target == null) {
target = document.elementFromPoint(clientPosition.x, clientPosition.y);
target = _getRealTargetFromPoint(clientPosition);
}

// Test if target is the drag avatar.
Expand All @@ -139,7 +146,7 @@ abstract class _EventManager {

// Target is the drag avatar, get element underneath.
drg.avatarHandler.avatar.style.visibility = 'hidden';
target = document.elementFromPoint(clientPosition.x, clientPosition.y);
target = _getRealTargetFromPoint(clientPosition);
drg.avatarHandler.avatar.style.visibility = 'visible';
}

Expand Down