Skip to content

Commit

Permalink
Fix drag and drop indices when block list contains a style element (#…
Browse files Browse the repository at this point in the history
…32776)

* Check for style elements

* Use wp-block classname

* Remove test that is no longer valid
  • Loading branch information
talldan authored and youknowriad committed Jun 25, 2021
1 parent dd3ebb0 commit 256e5cd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ export function getNearestBlockIndex( elements, position, orientation ) {
let candidateDistance;

elements.forEach( ( element, index ) => {
// Ensure the element is a block. It should have the `wp-block` class.
if ( ! element.classList.contains( 'wp-block' ) ) {
return;
}

const rect = element.getBoundingClientRect();
const [ distance, edge ] = getDistanceToNearestEdge(
position,
Expand Down Expand Up @@ -105,7 +100,10 @@ export default function useBlockDropZone( {
const onBlockDrop = useOnBlockDrop( targetRootClientId, targetBlockIndex );
const throttled = useThrottle(
useCallback( ( event, currentTarget ) => {
const blockElements = Array.from( currentTarget.children );
const blockElements = Array.from( currentTarget.children ).filter(
// Ensure the element is a block. It should have the `wp-block` class.
( element ) => element.classList.contains( 'wp-block' )
);
const targetIndex = getNearestBlockIndex(
blockElements,
{ x: event.clientX, y: event.clientY },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,6 @@ describe( 'getNearestBlockIndex', () => {
expect( result ).toBeUndefined();
} );

it( 'returns `undefined` if the elements do not have the `wp-block` class', () => {
const nonBlockElements = [
{ classList: createMockClassList( 'some-other-class' ) },
];
const position = { x: 0, y: 0 };
const orientation = 'horizontal';

const result = getNearestBlockIndex(
nonBlockElements,
position,
orientation
);

expect( result ).toBeUndefined();
} );

describe( 'Vertical block lists', () => {
const orientation = 'vertical';

Expand Down

0 comments on commit 256e5cd

Please sign in to comment.