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

Allow parent blocks to specify their block drop zone. #26049

Closed
talldan opened this issue Oct 13, 2020 · 3 comments · Fixed by #56312
Closed

Allow parent blocks to specify their block drop zone. #26049

talldan opened this issue Oct 13, 2020 · 3 comments · Fixed by #56312
Assignees
Labels
[Feature] Drag and Drop Drag and drop functionality when working with blocks [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement.

Comments

@talldan
Copy link
Contributor

talldan commented Oct 13, 2020

Is your feature request related to a problem? Please describe.
Presently when dragging and dropping into child block lists, the InnerBlocks component acts as a dropzone.

In technical terms, this happens because the block drop zone is implemented in the BlockList component, and uses a reference to the DOM element for the block list:
https://github.com/WordPress/gutenberg/blob/master/packages/block-editor/src/components/block-list/index.js#L108

Often the block list isn't or can't be styled to take up adequate space for drag and drop operations, and if a block list collapses to zero height (#25911), drag and drop isn't possible at all.

Preferably a block developer is able to specify any element in their block as the block drop zone to maximize usability.

Describe the solution you'd like
The useBlockDropZone hook is almost portable:

const dropTargetBlockIndex = useBlockDropZone( {
		element: ref,
		rootClientId,
} );

If this hook is used in a block edit, the dropTargetBlockIndex it returns could be passed into InnerBlocks:

<InnerBlocks dropTargetBlockIndex={ dropTargetBlockIndex } />

when this prop is passed, InnerBlocks could bypass its own useBlockDropZone hook.

Describe alternatives you've considered
I haven't looked into feasibility, but a supports.customBlockDropZone setting could also be a possibility. When this is present, a ref could be passed into the edit function:

edit( { blockDropZoneRef } ) {
  // ...
  return (
    <div ref={ blockDropZoneRef }>
        // ...
    </div>
  )
}

Which allows a block developer to specify which element should be considered a block drop zone.

@talldan talldan added [Feature] Drag and Drop Drag and drop functionality when working with blocks [Type] Enhancement A suggestion for improvement. labels Oct 13, 2020
@talldan talldan changed the title Allow parent blocks to specify their drop zone. Allow parent blocks to specify their block drop zone. Oct 14, 2020
@andrewserong
Copy link
Contributor

I've implemented this in #56070. It's currently __unstableDropZoneElement from the perspective of useInnerBlocksProps, so as it's unstable (and I haven't tested using it with container blocks yet), I'll leave this issue open for now.

@andrewserong
Copy link
Contributor

andrewserong commented Nov 20, 2023

Just sharing a screengrab of the problem that I think this issue is intended to address based on the comment from #56070 (comment). If we add a Cover block and attempt to drag blocks within it, you have to carefully hover over one of the inner blocks — the padding area within the Cover block is not treated as a dropzone, and so if you're dragging within the top or bottom areas of the Cover block, it thinks you want to drag before or after the block, instead of within it:

2023-11-20.15.11.59.mp4

It'll be worth seeing if the new dropZoneElement prop from #56070 helps us address this.

@andrewserong
Copy link
Contributor

Update: I've started a proof of concept over in #56312 that demonstrates that using dropZoneElement via useInnerBlocksProps and passing it a reference to the block's wrapper will fix the issue. Whether or not that's quite the right API for it, it seems a promising direction so far!

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 [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement.
Projects
None yet
2 participants