- 
                Notifications
    
You must be signed in to change notification settings  - Fork 4.6k
 
Drag and drop: Fix cursor feedback and add grabbing state in iframe editor #72629
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
base: trunk
Are you sure you want to change the base?
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.  | 
    
This reverts commit 77765a1.
| 
           Size Change: +150 B (+0.01%) Total Size: 2.19 MB 
 ℹ️ View Unchanged
  | 
    
| 
           This is cool @juanfra! I looked at this before and I thought overriding the cursor during HTML drag events was impossible and set at the OS level (unlike mouse events), but apparently that's not true. Cool! It seems to work fine for me in Chrome, but maybe I'm not testing the failure case correctly. I'll have a look through the code to understand how exactly it works.  | 
    
| event.preventDefault(); | ||
| cleanupRef.current(); | ||
| 
               | 
          ||
| // Blur the drag handle to clear the :active state. | 
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.
Could you elaborate on why the active state needs to be cleared?
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.
Sure :) since we set cursor: grabbing; for the active state of the “drag” button in the block toolbar, without clearing it, the cursor would stay grabbing even after the drop action. Clearing the active state ensures that when the “drag” button is hovered again, the cursor: grab style is shown as expected.
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'm actually noticing that blur won't be clearing the active state, so we'll have to try something else.
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.
Tbh this sounds like an accessibility concern
| cleanupRef.current(); | ||
| 
               | 
          ||
| // Blur the drag handle to clear the :active state. | ||
| if ( event.target instanceof HTMLElement ) { | 
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.
Since this element is not in an iframe, it's fine, but I find it generally better to explicitly get HTMLElement from defaultView to communicate what is expected.
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.
Makes sense. I’ll look into that and update it.
| 
           Actually, this only sets the styles for drag and drop from the block toolbar or list view right? You're not adjust any styles for direct drag and drop as for as I can see. Somehow the   | 
    
| 
           Thanks for taking a look @ellatrix ! 
 Yes, fortunately it’s possible — there are a few common approaches (some use cursor: move, others the grab/grabbing pattern, which feels the most intuitive to me). 
 Exactly, this PR builds on the existing logic that handled the body class for drag and drop cursors ( 
 Interesting. For the list view or the block toolbar? I’m not seeing that behavior in Chrome on my side. Chrome has been pretty erratic for me when it comes to this, and from what I’ve seen, it seems related to the dropEffect issue I mentioned earlier. There are a few issues reported on their repo.  | 
    
          
 Neither, I mean for direct block drag and drop (like images).  | 
    
What?
Fixes drag and drop cursor feedback in the block editor by ensuring cursor styles apply within the iframe context, and adds
cursor: grabbingstate when blocks are actively being dragged.Found while testing drag and drop improvements for 6.9
Why?
The current drag and drop experience has a cursor feedback issue: when dragging blocks, the body class that changes the cursor is applied to the parent document, but since the editor runs in an iframe, these cursor changes aren't visible to users. This creates a disconnect in the UX where the visual feedback doesn't match the interaction state. Also, we weren't showing the native
grabbingcursor during active drag operations.How?
cursor: grabbingCSS rule when blocks are actively being grabbed/draggedNote: There's a known limitation in Chrome where the
dropEffectproperty doesn't always update the cursor as expected during drag operations. Firefox and Safari handle this correctly. The fallback cursor styles still provide visual feedback in Chrome, though not as dynamically as in other browsers. So, maybe it's better to test this in Firefox.Testing Instructions
grabcursor, and when grabbing it should show thegrabbingcursor.Screenshots or screencast
drag-n-drop-cursor.mp4