Skip to content

Commit

Permalink
Cover block: Pass dropZoneElement reference to fix dragging and dropp…
Browse files Browse the repository at this point in the history
…ing within cover block area
  • Loading branch information
andrewserong committed Nov 20, 2023
1 parent d11351f commit b117ebe
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/block-library/src/cover/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { useEntityProp, store as coreStore } from '@wordpress/core-data';
import { useEffect, useMemo, useRef } from '@wordpress/element';
import { useEffect, useMemo, useRef, useState } from '@wordpress/element';
import { Placeholder, Spinner } from '@wordpress/components';
import { compose, useResizeObserver } from '@wordpress/compose';
import {
Expand Down Expand Up @@ -324,6 +324,10 @@ function CoverEdit( {
fontSize: hasFontSizes ? 'large' : undefined,
} );

// Use internal state instead of a ref to make sure that the component
// re-renders when the dropZoneElement updates.
const [ dropZoneElement, setDropZoneElement ] = useState( null );

const innerBlocksProps = useInnerBlocksProps(
{
className: 'wp-block-cover__inner-container',
Expand All @@ -335,6 +339,7 @@ function CoverEdit( {
templateInsertUpdatesSelection: true,
allowedBlocks,
templateLock,
__unstableDropZoneElement: dropZoneElement,
}
);

Expand Down Expand Up @@ -494,6 +499,7 @@ function CoverEdit( {
<TagName
{ ...blockProps }
className={ classnames( classes, blockProps.className ) }
ref={ setDropZoneElement }
style={ { ...style, ...blockProps.style } }
data-url={ url }
>
Expand Down

0 comments on commit b117ebe

Please sign in to comment.