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

Fix drag and drop in chrome when the document has iframes #9511

Merged
merged 3 commits into from
Sep 12, 2018

Conversation

oandregal
Copy link
Member

Fixes #6145

In Chrome, the dragend event won't be dispatched if an iframe is affected by the drag operation (moved as a result of dragging other nodes, etc). Chrome bug.

Testing

  • Create a post that contains an iframe. For example, you can add an embed block (twitter, youtube video, etc).
  • Drag it to several positions.
  • Drag other elements above and below it.

The expected result is that the drag-and-drop operation works and it's not stuck mid-drag.

@oandregal oandregal self-assigned this Aug 31, 2018
@oandregal oandregal added the [Type] Bug An existing feature does not function as intended label Aug 31, 2018
@oandregal oandregal added this to the 3.8 milestone Aug 31, 2018
@oandregal
Copy link
Member Author

oandregal commented Aug 31, 2018

Note that #9311 refactors the Draggable component. This PR will be rebased once the former is merged.

@@ -57,6 +64,13 @@ class Draggable extends Component {
this.cursorTop = event.clientY;
}

onDrop( ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that, as per the spec and tested in practice, the drop event is fired before the dragend event. So, an alternative approach to fix this would be to use the drop event in every case, as it is fired reliably AFAIK. That would require changing Draggable API to use the onDrop instead.

Because this bug only affect Chrome if the document has iframes, I feel more comfortable trying to limit the hack to that particular use case. I hope the Chrome team fix this at some point and if they do, we can remove the hack without affecting Draggable's API.

@@ -15,14 +15,20 @@ const cloneWrapperClass = 'components-draggable__clone';
const cloneHeightTransformationBreakpoint = 700;
const clonePadding = 20;

const isChromeUA = ( ) => /Chrome/.test( window.navigator.userAgent );
const documentHasIframes = ( ) => [ ...document.body.querySelectorAll( 'iframe' ) ].length > 0;
Copy link
Member Author

Choose a reason for hiding this comment

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

Shall we scope the iframe search to the .editor-block-list__layout element? I fear that if we do that it would break at some point if we decide to change the CSS classes we use.

Also, I'm not aware of any other areas that could potentially use iframes outside the editor. Is there any? If so, this would give false positives.

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 should scope the search at least to the #editor element. The WordPress.com notifications bar uses an iframe.

@oandregal oandregal added the [Feature] Drag and Drop Drag and drop functionality when working with blocks label Aug 31, 2018
See https://bugs.chromium.org/p/chromium/issues/detail?id=737691#c8
In Chrome, the dragend won't be dispatched is an iframe is affected
by the drag operation (moved as a result of dragging other nodes,
etc).
@youknowriad youknowriad modified the milestones: 3.8, 3.9 Sep 5, 2018
@youknowriad
Copy link
Contributor

Tested and confirmed the fix but I think design wise, it's not great. I wonder if we should show the block icon as a drag handle instead of removing the iframes which can cause weird states.

cc @jasmussen

@youknowriad youknowriad added the Needs Design Feedback Needs general design feedback. label Sep 7, 2018
@youknowriad
Copy link
Contributor

Oh I guess the iframe removal is already in master, so I guess I'm just going to approve here and we'll see if we can improve the drag handle for blocks with iframes later.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@youknowriad youknowriad removed the Needs Design Feedback Needs general design feedback. label Sep 7, 2018
@jasmussen
Copy link
Contributor

Given designs, perhaps we should merge this along wiht the improvements that are scheduled in add/drag-handle?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Drag and Drop Drag and drop functionality when working with blocks [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants