Skip to content

The annotations package breaks drop targets when dragging blocks #21172

Closed

Description

@herregroen

Describe the bug
When you load the annotations package the is-drop-target class introduced in #19514 doesn't show up as the filter in https://github.com/WordPress/gutenberg/blob/master/packages/annotations/src/block/index.js doesn't add additional classes but replaces them.

To reproduce
Steps to reproduce the behavior:

  1. Enqueue wp-annotations
  2. Drag a block
  3. You don't see any drop-targets and dragging blocks becomes much more difficult as the space these create is required.

Expected behavior
I expected the drop targets both to visually aid me as well as to provide sufficient space between elements to make dragging and dropping a user-friendly experience.

Additional context

  • The annotations package is being used by Yoast SEO and thus will be loaded on a large number of sites.

Activity

  1. added
    [Type] BugAn existing feature does not function as intended
    [Type] RegressionRelated to a regression in the latest release
    on Mar 26, 2020
  2. aduth commented on Mar 26, 2020

    @aduth
    Member

    Confirmed. It can also be reproduced in the default development environment by activating the "Gutenberg Test Plugin, Plugins API" plugin.

    Suggested fix: Annotations implementation should merge with incoming className prop.

  3. self-assigned this
    on Mar 26, 2020
  4. aduth commented on Mar 26, 2020

    @aduth
    Member

    See #21184 for fix.

  5. aduth commented on Mar 26, 2020

    @aduth
    Member

    cc @jorgefilipecosta This may be a regression slated to land for 5.4.

    As worst-case scenario in case it's too late for the release, a possible workaround would be to create filter(s) on editor.BlockListBlock which restores the is-drop-target class name.

    Untested code, but roughly:

    addFilter(
    	'editor.BlockListBlock',
    	'my-plugin/store-block-class-name',
    	function( OriginalComponent ) {
    		return function( props ) {
    			if ( props.className ) {
    				props = Object.assign(
    					{ 'data-original-class-name': props.className },
    					props
    				);
    			}
    
    			return wp.element.createElement(
    				OriginalComponent,
    				props
    			);
    		}
    	},
    	5
    );
    
    addFilter(
    	'editor.BlockListBlock',
    	'my-plugin/restore-block-class-name',
    	function( OriginalComponent ) {
    		return function( props ) {
    			return wp.element.createElement(
    				OriginalComponent,
    				Object.assign( {}, props, {
    					className: [
    						props.className,
    						props[ 'data-original-class-name' ],
    					].filter( Boolean ).join( ' ' ),
    				} )
    			);
    		}
    	},
    	20
    );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[Feature] AnnotationsAdding annotation functionality[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended[Type] RegressionRelated to a regression in the latest release

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions