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

Style hooks - default values cause extra wrappers and block errors in editor for standard blocks. #24387

Open
Addison-Stavlo opened this issue Aug 5, 2020 · 5 comments
Labels
[Feature] Custom Editor Styles Functionality for adding custom editor styles [Type] Bug An existing feature does not function as intended

Comments

@Addison-Stavlo
Copy link
Contributor

Describe the bug
Semi-related to #24363.

Style hooks seem to be written with the intent to support default styles to be defined on the block- ex:

// allow blocks to specify their own attribute definition with default values if needed.
if ( ! settings.attributes.backgroundColor ) {
Object.assign( settings.attributes, {
backgroundColor: {
type: 'string',
},
} );

However, in practice this seems to not play nice in the editor. With standard blocks (reproduced with Paragraph and Heading), default styles add extra wrappers in the editor and can break the blocks.

To reproduce

Below I will explore this with a standard block, "Paragraph".

  1. Add the following to attributes in Paragraph's block.json file:
		"textColor": {
			"type": "string",
			"default": "secondary"
		},
		"backgroundColor": {
			"type": "string",
			"default": "primary"
		},
		"fontSize": {
			"type": "string",
			"default": "large"
		}
  1. Load the editor and add/edit a new paragraph. It should have the default values as expected:
    Screen Shot 2020-08-05 at 1 02 16 PM

  2. Select custom values for the fontSize, backgroundColor, and textColor and save:
    Screen Shot 2020-08-05 at 1 03 57 PM

  3. Reload the editor, notice the block has a different size and indentation:
    Screen Shot 2020-08-05 at 1 04 38 PM

Inspecting the element reveals that there is a <p> element nested inside the Paragraph wrapper:
Screen Shot 2020-08-05 at 1 06 07 PM

  1. Try changing to a different custom background color for the block. Notice the background is only applied to outer wrapper:
    Screen Shot 2020-08-05 at 1 07 56 PM

  2. Save and reload the editor, you may find the block has broken:
    Screen Shot 2020-08-05 at 1 08 41 PM

Expected behavior
Expected to not have a second wrapper and broken block.

@Addison-Stavlo
Copy link
Contributor Author

Addison-Stavlo commented Aug 5, 2020

FYI @youknowriad (not to be confused with #24363)

@youknowriad
Copy link
Contributor

This only applies to paragraphs right?

To support p-less paragraph blocks we have a "deprecated" version for the paragraph block used to auto-add the p wrapper. I think that's probably what's causing the double paragraphs here. I saw in the past that this deprecated version of paragraph block caused other similar issues (double p), so I wonder if we can rework it and try to apply it only when we detect p-less paragraphs.

@Addison-Stavlo
Copy link
Contributor Author

This only applies to paragraphs right?

It seems to be the case with the heading block as well. I haven't tested beyond those two currently.

@youknowriad
Copy link
Contributor

It seems to be the case with the heading block as well. I haven't tested beyond those two currently.

In that case, it's a different story independent with the "p -less" deprecation.

@annezazu annezazu added [Feature] Custom Editor Styles Functionality for adding custom editor styles [Type] Bug An existing feature does not function as intended labels Sep 2, 2020
@annezazu
Copy link
Contributor

annezazu commented Sep 2, 2020

Just an FYI that I did the best I could to label this but if others have a better possible label, please update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Custom Editor Styles Functionality for adding custom editor styles [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

3 participants