-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Adding custom className in editor.BlockEdit filter, no longer works in 7.7 #20849
Comments
Looks like we're overwriting
Let's add |
Can I work on this issue? |
@cguntur: Go for it! I'll assign you. Feel free to reach out to me on the WordPress Slack if you need any help. My username is |
When I use <BlockEdit { ...blockProps } />, with the above code, I can see the max width option in the sidebar, but don't see the actual block in the editor. I tried with another example and when I use (..blockProps), the same thing happens. Am I missing anything? I added props.className gutenberg/packages/block-editor/src/components/block-edit/edit.js, but I am not able to test if the fix works. |
@cguntur: Could you create a PR? That will let me see the code and help 🙂 |
Here is the PR - #25846. I tried testing this with the code mentioned above, but ,I couldn't get the class names to show up in the editor even after I added props.className in the specific file when I use editor.BlockEdit The only way the classes show up in the editor is when I use editor.BlockListBlock. |
Since the API Version 2 with the light block wrapper the class name passed in via props isn't used anymore. Instead the The way you can already go about adding custom class names to the wrapping block element is by using the `` hook like so: /**
* addAdditionalPropertiesInEditor
*/
const addAdditionalPropertiesInEditor = createHigherOrderComponent((BlockList) => {
return (props) => {
const { name, attributes, className, } = props;
// return early from the block modification
if (! name === 'core/heading' ) {
return <BlockList {...props} />;
}
const additionalClassName = 'hello-world';
const newClassName = classnames(className, additionalClassName);
return (
<BlockList
{...props}
className={newClassName}
/>
);
};
}, 'addAdditionalPropertiesInEditor');
addFilter(
'editor.BlockListBlock',
'namespace/addAdditionalPropertiesInEditor',
addAdditionalPropertiesInEditor,
); Because of this I believe this ticket can be closed out. Please tell me if I'm understanding anything incorrectly in which case we can gladly reopen the issue :) |
@fabiankaegy could you please help me understand why I'm unable to filter out two specific classes from my 'core/post-template' block variation? I'm trying to remove the classes is-layout-flow and wp-block-post-template-is-layout-flow, but className appears to be undefined when I attempt to filter them out. Any insights would be greatly appreciated! Here is my function:
|
Describe the bug
When adding custom attributes to a paragraph or heading block, it is no longer possible to also add a
className
within theeditor.BlockEdit
filter. Before 7.7, this was possible with the code sample provided below.To reproduce
Steps to reproduce the behavior with the above code being enqueued:
Expected behavior
Previously to 7.7, I was able to use this same code and add the
has-max-width-${maxWidth}
className to the BlockEdit element. I tracked the PR down that caused this to change here, https://github.com/WordPress/gutenberg/pull/20658/files#diff-7b64e61cdb441265be8d707b44abad80L158. The same applies tocore/column
andcore/heading
blocks.Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: