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

editor-styles-wrapper effecting previews in the components panel #11997

Closed
m-e-h opened this issue Nov 16, 2018 · 9 comments · Fixed by #12212
Closed

editor-styles-wrapper effecting previews in the components panel #11997

m-e-h opened this issue Nov 16, 2018 · 9 comments · Fixed by #12212
Labels
Needs Testing Needs further testing to be confirmed.

Comments

@m-e-h
Copy link
Member

m-e-h commented Nov 16, 2018

button-preview

To Reproduce
Steps to reproduce the behavior:
1.Create a button in Twenty Seventeen from the WP 5.0 Branch
2. Checkout the button preview

Cause
This: https://github.com/WordPress/WordPress/blob/5.0-branch/wp-content/themes/twentyseventeen/assets/css/editor-blocks.css#L724

And this: https://github.com/WordPress/WordPress/blob/5.0-branch/wp-content/themes/twentyseventeen/assets/css/editor-style.css#L27

Desktop (please complete the following information):

  • Ubuntu 18.04
  • Browser Firefox

Additional context

  • Gutenberg 4.4
@m-e-h
Copy link
Member Author

m-e-h commented Nov 16, 2018

Twenty Sixteen too.
twentysixteen
Also because of body margins.

@designsimply
Copy link
Member

Noting to test these but also I think theme-specific issues should go to each theme's respective repository. I'll look into it!

@m-e-h
Copy link
Member Author

m-e-h commented Nov 18, 2018

I think this is more of an issue with the editor-styles-wrapper than any specific theme. It's only an issue with these two themes because their design adds margins to the body. It could easily be an issue with any other themes body styles as well.

Twenty Seventeen has this:

body {
	background-color: #fff;
	color: #333;
	margin: 20px 40px;
	max-width: 580px;
}

Which after the editor-styles thing mutates the selectors, it becomes this:

.editor-styles-wrapper {
	background-color: #fff;
	color: #333;
	margin: 20px 40px;
	max-width: 580px;
}

This interferes with the button preview because the editor-styles-wrapper class is actually being added to a div that wraps the button in the components-panel.
button-panel

@m-e-h m-e-h mentioned this issue Nov 19, 2018
4 tasks
@m-e-h m-e-h changed the title Twenty Seventeen has a broken button preview in the components panel editor-styles-wrapper effecting button preview in the components panel Nov 20, 2018
@m-e-h
Copy link
Member Author

m-e-h commented Nov 20, 2018

Here you can see the issue as I toggle the body margins on the .editor-styles-wrapper
button-wrapper

@m-e-h
Copy link
Member Author

m-e-h commented Nov 20, 2018

Not exclusive to buttons #12066 (comment)

@m-e-h m-e-h changed the title editor-styles-wrapper effecting button preview in the components panel editor-styles-wrapper effecting previews in the components panel Nov 20, 2018
@jasmussen
Copy link
Contributor

Thanks for the ticket, but can you help me understand exactly what the issue is? I realize there's additional margin on items in the preview, and prior to the pullquote gap I just fixed, there was a white gap in the right side. However the presence of the editor style wrapper in the preview is intentional, insofar as the items in the preview should inherit styles that the theme provides. The bug is not obvious to me (though forgive me if it should be, I've just had a sick kid for the past week so I'm slightly zombified).

@m-e-h
Copy link
Member Author

m-e-h commented Nov 21, 2018

I feel your pain @jasmussen . Having a sick kid is the worst!

The issue here boils down to user styles being injected into the components-panel.
This is done when we map the user's body styles to the .editor-styles-wrapper.
So this is only an issue if they add_theme_support(editor-styles).

In this case Twenty Seventeen from the 5.0 branch has margin: 20px 40px on the body so now they also have margin: 20px 40px on .editor-styles-wrapper which is squeezing the button out of the window.
Combine that with the body{background-color: #fff} and the margin-top: 2em that Twenty Seventeen has on the Button itself, and you've got a little white rectangle hovering over the button and causing the gap you were seeing in the box-shadow border.

Hope that makes sense.
A quick band-aid for this particular case and probably others would be:

.components-panel .wp-block-button__link {
    margin: 0;
}

.components-panel .editor-styles-wrapper {
    margin: 0;
}

But we should probably be more anticipatory of other common body styles that may break the preview.
Something like this:

.components-panel .editor-styles-wrapper {
    margin: 0;
    padding: 0;
    overflow: visible;
    min-height: auto;
}

I'm not going to beat my drum about #10178 anymore but I honestly thing we need to be doing more defensive coding. Mixing user styles with app styles can quickly turn into a game of whack-a-mole.

@jasmussen
Copy link
Contributor

Thank you for the clarification. I didn't mean for you to stop beating that drum, I think it's an important one, and with your clarifications even more-so.

I suppose in light of that additional information, I still think that we should consider editor styles to b in their infancy and be be mindful with how far we're trying to go with them. However the purpose of doing this is exactly so tickets like yours can be raised and addressed as we continue to refine and improve the situation.

For example, I think Shadow DOM has huge potential here. Sadly it's not widely supported: https://caniuse.com/#feat=shadowdom

Element queries, similarly, will go a long way, but those are also not well supported and the polyfill isn't compatible with react and modern JS frameworks.

Finally, CSS display: contents; can probably go farther than any single other thing in improving the situation. https://css-tricks.com/get-ready-for-display-contents/

jasmussen pushed a commit that referenced this issue Nov 22, 2018
Hopefully fixes #11997.

It polishes the preview code a bit to be leaner and more readable. But mostly it adds a fwe CSS style overrides that it might inherit from the theme.
@jasmussen
Copy link
Contributor

Submitted #12212 to potentially fix this.

youknowriad pushed a commit that referenced this issue Nov 23, 2018
Hopefully fixes #11997.

It polishes the preview code a bit to be leaner and more readable. But mostly it adds a fwe CSS style overrides that it might inherit from the theme.
youknowriad pushed a commit that referenced this issue Nov 29, 2018
Hopefully fixes #11997.

It polishes the preview code a bit to be leaner and more readable. But mostly it adds a fwe CSS style overrides that it might inherit from the theme.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Testing Needs further testing to be confirmed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants