πŸ’Ž PREMIUM: Ndiego/block visibility/issues/ - HD Photos!

Skip to content

Overrides custom class names added via editor.BlockListBlock hookΒ #61

@fabiankaegy

Description

@fabiankaegy

Description

Custom class names that get added to the BlockList element via the editor.BlockListBlock hook get overwritten by custom classnames from Block Visibility Plugin.

let classes = classnames(
{
'block-visibility__is-hidden': isHidden,
},
controlsClass
);
if ( classes ) {
classes = classes + ' block-visibility__has-visibility';
}
classes = applyFilters(
'blockVisibility.contextualIndicatorClasses',
classes
);
// Deprecated filter as of v2.5.1, use contextualIndicatorClasses instead.
classes = applyFilters(
'blockVisibility.conditionalIndicatorClasses',
classes
);
return <BlockListBlock { ...props } className={ classes } />;

I believe this could be fixed by doing the following:

let classes = classnames( 
 	{ 
 		'block-visibility__is-hidden': isHidden, 
 	},
 	props.className, 
 	controlsClass 
 ); 

Here is an example of how it is done in core: https://github.com/WordPress/gutenberg/blob/70ba9218ae53e31d2c26689eed2e698dcea7f3aa/packages/block-editor/src/hooks/layout.js#L457-L460

Step-by-step reproduction instructions

Add another sample plugin that tries to filter editor.BlockListBlock and adds a custom class name to the element. See that this class doesn't get added when the Block Visibility Plugin is enabled.

Expected behavior

The custom classNames added in the filter get added

Actual behavior

Only the classes from Block Visibility get added. It overrides custom classes added by other filters

Screenshots or screen recording (optional)

System information

  • Block Visibility version: 2.5.2
  • Block Visibility Pro version: Not installed
  • WordPress version: 6.1.1
  • Gutenberg version: 15.0
  • Are all plugins except Block Visibility, Block Visibility Pro (if installed), and Gutenberg (if installed) deactivated? Yes
  • Are you using a default theme (e.g. Twenty Twenty-One)? Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working, looks like a πŸ›.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions