-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Drag and drop: fix firefox compat logic #67439
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +199 B (+0.01%) Total Size: 1.83 MB
ℹ️ View Unchanged
|
@@ -125,7 +123,7 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) { | |||
isEnabled: isSectionBlock, | |||
} ), | |||
useScrollIntoView( { isSelected } ), | |||
canDrag ? ffDragRef : undefined, | |||
canMove ? ffDragRef : undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes the issue where you can't drag a quote block after selecting a paragraph inside it in trunk.
@@ -13,13 +75,9 @@ import { useRefEffect } from '@wordpress/compose'; | |||
*/ | |||
export function useFirefoxDraggableCompatibility() { | |||
return useRefEffect( ( node ) => { | |||
function onDown( event ) { | |||
node.draggable = ! event.target.isContentEditable; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice that we're currently setting all blocks to be draggable whenever a non editable element is clicked! Also, we're constantly setting draggable true/false for all blocks on click.
node.draggable = ! event.target.isContentEditable; | ||
} | ||
const { ownerDocument } = node; | ||
ownerDocument.addEventListener( 'pointerdown', onDown ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also opted to avoid adding an event listener for every single block and maintain a set instead.
Thanks @youknowriad! |
Co-authored-by: ellatrix <[email protected]> Co-authored-by: youknowriad <[email protected]>
What? Why? How?
While trying
cursor:grab
for draggable blocks, I noticed thatdraggable
is currently being set to true for a lot of block by accident that shouldn't be draggable after you click on them. That's because of a mistake in the Firefox compatibility logic. It doesn't check if the block is draggable first. We'll also have to set a temporary attribute to store the previous state so we only restore it totrue
when it was previously draggable.Also fixes an edge case where you can't drag the block you select an inner block.
Also improves the performance of this hook by only adding a single event handler.
Testing Instructions
Use Firefox. Make sure we the compatibility logic still works; it should still be possible to select within editable fields within a block such as the quote block.
Also click in a paragraph for example and out of it. The paragraph should not be left with a
draggable
attribute.Now also click a paragraph in a quote and then try to drag the quote. In trunk this doesn't work. With this PR it does.
Testing Instructions for Keyboard
Screenshots or screencast