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

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

Closed
fabiankaegy opened this issue Jan 23, 2023 · 1 comment · Fixed by #62
Closed

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

fabiankaegy opened this issue Jan 23, 2023 · 1 comment · Fixed by #62
Labels
Bug Something isn't working, looks like a 🐛.

Comments

@fabiankaegy
Copy link
Contributor

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
@ndiego
Copy link
Owner

ndiego commented Jan 24, 2023

Great catch on this. Thanks for taking the time to put together a PR as well! 💪

@ndiego ndiego added the Bug Something isn't working, looks like a 🐛. label Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working, looks like a 🐛.
Projects
None yet
2 participants