Skip to content

fix(cdk/drag-drop): not stopping drag if page is blurred #17848

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Dec 1, 2019

Currently the only way to stop a drag sequence is via a mouseup/touchend event or by destroying the instance, however if the page loses focus while dragging the events won't be dispatched anymore and user will have to click again to stop dragging. These changes add some extra code that listens for blur events on the window and stops dragging.

Fixes #17537.

@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release labels Dec 1, 2019
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Dec 1, 2019
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

Would it also make sense to use the Page Visibility API and abort dragging on that as well? (maybe a follow up)

// If the page is blurred while dragging (e.g. there was an `alert` or the browser window was
// minimized) we won't get a mouseup/touchend so we need to use a different event to stop the
// drag sequence. Use the last known location to figure out where the element should be dropped.
this._blurSubscription = this._dragDropRegistry.pageBlurred.subscribe(() => {
Copy link
Member

Choose a reason for hiding this comment

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

I would have thought that this would be treated as cancelling the drag sequence instead of completing it, since the dragged item might be somewhere the user doesn't want to drop.

Copy link
Member Author

Choose a reason for hiding this comment

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

We could do that, but it won't be very smooth, because the list could've been shuffled already and we'd have to snap it back into place. Also it would be inconsistent, because we'd have to avoid emitting the dropped event, even though we've emitted the start, move etc. events.

Copy link
Member

Choose a reason for hiding this comment

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

Do users currently have a way to cancel a drag? E.g., is I want to let people press escape to abort?

Copy link
Member Author

Choose a reason for hiding this comment

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

They don't. I've had it as a low-priority task on my list to add an API for it, but I haven't had the time for it.

Copy link
Member

Choose a reason for hiding this comment

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

I think I would want to collect more data on this before committing to the behavior (drop vs. abort)- maybe trying it out with a few people and seeing what they expect to happen

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we have people that are willing to try it out? This is a bit of an edge case to begin with so I don't know how much time we want to spend on it.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe just a twitter poll?

@crisbeto
Copy link
Member Author

crisbeto commented Dec 4, 2019

@jelbourn as I understand it, the page visibility API only emits when the user switches to a different tab or they minimize the window. I think the blur approach here is better, because it handles the same as the API, as well as when the user gets an alert.

@crisbeto crisbeto force-pushed the 17537/drag-drop-window-blur branch from b4dacbe to c0a1b15 Compare February 16, 2020 17:02
@crisbeto crisbeto force-pushed the 17537/drag-drop-window-blur branch from c0a1b15 to cc54183 Compare March 3, 2020 21:31
@crisbeto crisbeto force-pushed the 17537/drag-drop-window-blur branch from cc54183 to 1437e12 Compare May 3, 2020 13:24
@crisbeto crisbeto force-pushed the 17537/drag-drop-window-blur branch from 1437e12 to a7a25cd Compare July 8, 2020 20:59
@crisbeto
Copy link
Member Author

@jelbourn I think we kind of forgot about this PR. I don't think it's a big enough issue that we'd have to poll the community about it so can we keep it moving?

@jelbourn
Copy link
Member

I still think that the page blurring should be treated as an abort rather than a drop

@crisbeto crisbeto force-pushed the 17537/drag-drop-window-blur branch from a7a25cd to 698107f Compare November 26, 2020 17:43
@crisbeto crisbeto changed the title fix(drag-drop): not stopping drag if page is blurred fix(cdk/drag-drop): not stopping drag if page is blurred Nov 26, 2020
@crisbeto crisbeto force-pushed the 17537/drag-drop-window-blur branch from 698107f to cae87f9 Compare January 7, 2021 13:10
@crisbeto crisbeto force-pushed the 17537/drag-drop-window-blur branch from cae87f9 to 5cd1b28 Compare April 5, 2021 16:35
@crisbeto crisbeto force-pushed the 17537/drag-drop-window-blur branch from 5cd1b28 to 3d53e08 Compare May 5, 2021 19:32
Currently the only way to stop a drag sequence is via a `mouseup`/`touchend` event or
by destroying the instance, however if the page loses focus while dragging the events
won't be dispatched anymore and user will have to click again to stop dragging. These
changes add some extra code that listens for `blur` events on the `window` and stops dragging.

Fixes angular#17537.
@crisbeto crisbeto force-pushed the 17537/drag-drop-window-blur branch from 3d53e08 to cd3b833 Compare June 29, 2021 18:43
@andrewseguin andrewseguin removed the cla: yes PR author has agreed to Google's Contributor License Agreement label Dec 28, 2021
@andrewseguin andrewseguin removed the P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent label Mar 28, 2022
@josephperrott josephperrott requested review from a team as code owners December 18, 2024 17:40
@josephperrott josephperrott requested review from amysorto and removed request for a team December 18, 2024 17:40
@josephperrott josephperrott requested review from mmalerba and removed request for a team December 18, 2024 17:40
@mmalerba mmalerba removed their request for review February 20, 2025 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

drag and drop | item continue to drag when something interrupt it
6 participants