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

Try: Remove canvas padding. #22213

Merged
merged 3 commits into from
Jun 22, 2020
Merged

Conversation

jasmussen
Copy link
Contributor

This PR removes the 14px on mobile, 36px on desktop breakpoints padding that is applied to the root container.

In the previous iteration of the editor, this padding was necessary to:

  • on mobile, show the 14px block border that sat 14px outside of the selected block.
  • on desktop breakpoints, show both the 14px block padding, and make room for the side UI (movers)

Because both of those elements are no longer present, we can remove this padding. This benefits themes that try to style the editor as best possible to match the frontend.

These screenshots show a theme that loads an editor style that goes almost edge to edge — Hello World should sit 10px from the edge:

Screenshot 2020-05-08 at 10 43 49

Same on mobile:

Screenshot 2020-05-08 at 10 43 58

Full-wide blocks compensated for this, I have removed that compensation, and it works as intended:

Screenshot 2020-05-08 at 10 45 43

Those 10px are intended from the theme, and compare with how that theme looks in master:

Screenshot 2020-05-08 at 10 53 48

It still works fine in the editor when no editor style is loaded:

Screenshot 2020-05-08 at 10 47 46

This PR does not appear to have negative effects in TwentyTwenty:

Screenshot 2020-05-08 at 10 51 07

There's an issue in TwentyNineteen:

Screenshot 2020-05-08 at 10 51 24

There's also an issue with TwentyNineteen in master, but as you can see from the scroll distance, it's been made slightly worse with this PR:

Screenshot 2020-05-08 at 10 54 34

I think it's an important code quality improvement to make, so worth fixing in TwentyNineteen, which probably double-compensates for margins that we are removing here.

@jasmussen jasmussen added [Type] Code Quality Issues or PRs that relate to code quality [Feature] Custom Editor Styles Functionality for adding custom editor styles labels May 8, 2020
@jasmussen jasmussen requested review from youknowriad and kjellr May 8, 2020 08:56
@jasmussen jasmussen requested a review from ellatrix as a code owner May 8, 2020 08:56
@jasmussen jasmussen self-assigned this May 8, 2020
@github-actions
Copy link

github-actions bot commented May 8, 2020

Size Change: -42 B (0%)

Total Size: 1.12 MB

Filename Size Change
build/block-editor/index.js 107 kB -10 B (0%)
build/block-editor/style-rtl.css 10.7 kB -44 B (0%)
build/block-editor/style.css 10.6 kB -47 B (0%)
build/block-library/index.js 129 kB -28 B (0%)
build/edit-post/style-rtl.css 5.48 kB -21 B (0%)
build/edit-post/style.css 5.47 kB -23 B (0%)
build/editor/editor-styles-rtl.css 537 B +69 B (12%) ⚠️
build/editor/editor-styles.css 539 B +70 B (12%) ⚠️
build/editor/index.js 44.8 kB -8 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.62 kB 0 B
build/api-fetch/index.js 3.4 kB 0 B
build/autop/index.js 2.82 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 7.26 kB 0 B
build/block-directory/style-rtl.css 937 B 0 B
build/block-directory/style.css 937 B 0 B
build/block-library/editor-rtl.css 7.59 kB 0 B
build/block-library/editor.css 7.59 kB 0 B
build/block-library/style-rtl.css 8.02 kB 0 B
build/block-library/style.css 8.02 kB 0 B
build/block-library/theme-rtl.css 730 B 0 B
build/block-library/theme.css 732 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 48.1 kB 0 B
build/components/index.js 195 kB 0 B
build/components/style-rtl.css 15.8 kB 0 B
build/components/style.css 15.7 kB 0 B
build/compose/index.js 9.6 kB 0 B
build/core-data/index.js 11.4 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/data/index.js 8.44 kB 0 B
build/date/index.js 5.47 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 569 B 0 B
build/dom/index.js 3.17 kB 0 B
build/edit-navigation/index.js 8.26 kB 0 B
build/edit-navigation/style-rtl.css 1.02 kB 0 B
build/edit-navigation/style.css 1.02 kB 0 B
build/edit-post/index.js 303 kB 0 B
build/edit-site/index.js 16.7 kB 0 B
build/edit-site/style-rtl.css 3.02 kB 0 B
build/edit-site/style.css 3.02 kB 0 B
build/edit-widgets/index.js 9.33 kB 0 B
build/edit-widgets/style-rtl.css 2.42 kB 0 B
build/edit-widgets/style.css 2.42 kB 0 B
build/editor/style-rtl.css 3.81 kB 0 B
build/editor/style.css 3.81 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.72 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 710 B 0 B
build/keyboard-shortcuts/index.js 2.51 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.13 kB 0 B
build/list-reusable-blocks/style-rtl.css 450 B 0 B
build/list-reusable-blocks/style.css 451 B 0 B
build/media-utils/index.js 5.3 kB 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/index.js 3.4 kB 0 B
build/nux/style-rtl.css 663 B 0 B
build/nux/style.css 660 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.5 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/rich-text/index.js 14 kB 0 B
build/server-side-render/index.js 2.68 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.28 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.85 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@youknowriad
Copy link
Contributor

I like this a lot but i did try this recently and had issues on mobile where the text was starting from the edge. (probably one of the 20* themes, i'll have to try again to confirm though).

@jasmussen
Copy link
Contributor Author

jasmussen commented May 8, 2020

Thank you! If you manage to find the theme you saw this in, I'm happy to think of edgecases and fixes.

Edit: Actually I've reproduced, it's when there's no editor style. Let me take a look.

@youknowriad
Copy link
Contributor

youknowriad commented May 8, 2020

Capture d’écran 2020-05-08 à 1 00 48 PM

I have this on 2020, it's not broken but there's no padding defined. Do you think it should be the theme responsibility to define the mobile padding?

@youknowriad youknowriad added the [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. label May 8, 2020
@jasmussen
Copy link
Contributor Author

I think it is, yes, but I also think that we have to handle it for the vanilla styles (i.e. no editor style). I have an idea that I'll try out and then we can let some opinions trickle in.

@jasmussen
Copy link
Contributor Author

So, to expand a bit — ultimately I think the goal is for themes to be able to load the same, or as close to as possible, CSS file into the editor as they load into the theme.

Every theme handles mobile like this — some add padding to the body, some apply something like max-width: calc(100% - 20px);. These styles should be allowed to work in the editor also.

That was actually my idea to try — add a calc-based max-width and then override at the mobile breakpoint. However that adds specificity that we don't want to add.

So I have two ideas for moving forward:

  1. Is to rewind a little bit this PR, and re-apply the padding, but 1 padding instead of changing it at the mobile breakpoint, and then a smaller padding so it's not so often you feel the need to change it.
  2. We consider whether we should create a "vanilla styles" stylesheet, that is loaded into the editor ONLY when a theme does not register an editor style.

Option 2 would benefit in other ways too, as we'd be able to move a couple of our baseline styles over in that stylesheet, so that themes that do have editor styles don't have to deal with them. What do you think?

@youknowriad
Copy link
Contributor

We consider whether we should create a "vanilla styles" stylesheet, that is loaded into the editor ONLY when a theme does not register an editor style.

To be fair, that was the initial idea of the "editor-styles.scss" stylesheet. it seems that it changed at some point and that it was always loaded in the end (I suspect during the 5.0 merge) but I missed when this happened.

@jasmussen
Copy link
Contributor Author

Nice. Should we revisit that?

@youknowriad
Copy link
Contributor

@jasmussen maybe but I'm afraid about the theme impact, these days we can't change anything without breaking changes :(

@jasmussen
Copy link
Contributor Author

Yep, I feel you!

I think it's something we should do at some point — but I'm happy to go the conservative route for now.

Perhaps if/when we have a combination of iframe and lighter DOM changes, we can bundle together a "careful with the upgrade" package, tear the bandaid off.

@youknowriad
Copy link
Contributor

Thinking how adding the "no-editor-styles" stylesheet would solve the issue for 2020 and similar themes though? It seems like it wouldn't?

@jasmussen
Copy link
Contributor Author

Well that's the thing, 2020 assumes the padding is there and does nothing, but it should, because it does go for the frontend.

There's an ugly transition period for some themes, sure. But there will be for lighter dom block changes also, there were for margin changes in the past. I'm not excited for such changes to happen, but I also think it's important to look at what the "right" solution is, even if that's not something we'll get to immediately.

@jasmussen jasmussen force-pushed the try/remove-left-right-canvas-padding branch from d04125f to 185412b Compare May 11, 2020 10:53
@jasmussen
Copy link
Contributor Author

To be fair, that was the initial idea of the "editor-styles.scss" stylesheet. it seems that it changed at some point and that it was always loaded in the end (I suspect during the 5.0 merge) but I missed when this happened.

So, I just tested, it appears that the contents of editor-styles.scss are indeed only output in the editor. I looked for the styles on the frontend but none appeared to seep through.

So that's the stylesheet that I was asking for, and I've added 10px clearace to the body there in 185412b.

What do you think?

@jasmussen
Copy link
Contributor Author

If we don't compensate fullwide blocks for the newly added 10px padding, we get this:

Screenshot 2020-05-11 at 12 55 48

Screenshot 2020-05-11 at 12 55 59

Screenshot 2020-05-11 at 12 56 21

Screenshot 2020-05-11 at 12 56 36

However I re-added that padding, and we now get this:

Screenshot 2020-05-11 at 13 00 25

Screenshot 2020-05-11 at 13 00 34

This makes it a much "safer" pull request. There's still that helper padding all around. But it's smaller (10px), it doesn't add specificity by growing at the breakpoint, and it's easy for themes to override.

@jasmussen jasmussen force-pushed the try/remove-left-right-canvas-padding branch from 087806f to 87c97b2 Compare May 11, 2020 12:27
Copy link
Member

@ZebulanStanphill ZebulanStanphill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code-wise, looks good to me.

@jasmussen jasmussen force-pushed the try/remove-left-right-canvas-padding branch from 87c97b2 to 01b2cc4 Compare May 12, 2020 08:41
// These paddings and margins are removed from the BlockPreview component's style
// Any change need to be reflected there.
// The editor-styles.scss file adds 10px padding all around the canvas, to ensure blocks aren't edge to edge on mobile.
// For full-wide blocks, we compensate for these 10px.
.block-editor-block-list__layout.is-root-container {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move these padding resets to the same file where the padding is added?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of 44e945f that would move it to editor-styles.scss. Happy to move it there if you feel it's appropriate? I personally like it because it keeps it together, but it feels... wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to be able to do this:

body {
	font-family: $editor-font;
	font-size: $editor-font-size;
	line-height: $editor-line-height;
	color: $dark-gray-primary;
	padding: 10px;

	// For full-wide blocks, we compensate for these 10px.
	> .wp-block[data-align="full"] {
		margin-left: -10px;
		margin-right: -10px;
	}
}

but body maps to editor-styles-wrapper, and block-editor__typewriter is the immediate child of that. So we have to target .is-root-container, which we can, but it's not quite as nice. I.e. this works:

body {
	font-family: $editor-font;
	font-size: $editor-font-size;
	line-height: $editor-line-height;
	color: $dark-gray-primary;
	padding: 10px;
}

// For full-wide blocks, we compensate for these 10px.
.is-root-container > .wp-block[data-align="full"] {
	margin-left: -10px;
	margin-right: -10px;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use the full selector .block-editor-block-list__layout.is-root-container but I think that's a good approach personally.

@jasmussen jasmussen force-pushed the try/remove-left-right-canvas-padding branch from c6db591 to ef1c14f Compare May 13, 2020 08:14
@jasmussen
Copy link
Contributor Author

I can't get the tests to pass on this one. I've tried restarting them multiple times, but they keep failing. I would appreciate any insights into whether the failure might be legitimate or not. It's CSS only so it's a bit confusing.

@jasmussen jasmussen force-pushed the try/remove-left-right-canvas-padding branch from ef1c14f to 45628aa Compare May 13, 2020 12:31
@jasmussen jasmussen force-pushed the try/remove-left-right-canvas-padding branch 7 times, most recently from c705201 to 2b7f4a0 Compare June 18, 2020 17:00
@jasmussen jasmussen mentioned this pull request Jun 19, 2020
@jasmussen jasmussen force-pushed the try/remove-left-right-canvas-padding branch from 2b7f4a0 to edf32d0 Compare June 22, 2020 06:28
This PR removes the 14px on mobile, 36px on desktop breakpoints padding that is applied to the root container.

In the previous iteration of the editor, this padding was necessary to:

- on mobile, show the 14px block border that sat 14px outside of the selected block.
- on desktop breakpoints, show both the 14px block padding, and make room for the side UI (movers)

Because both of those elements are no longer present, we can remove this padding.
@jasmussen jasmussen force-pushed the try/remove-left-right-canvas-padding branch from edf32d0 to 4370b73 Compare June 22, 2020 07:46
@@ -21,6 +21,9 @@ describe( 'TypeWriter', () => {
// Create first block.
await page.keyboard.press( 'Enter' );

// Create second block.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ellatrix Not urgent, but when you have a moment I'd love your take on why this specific commit makes the tests pass.

For context, this PR changes the padding of the editing canvas to be smaller. This leaves more room for themes that don't add this padding themselves, i.e. 2020 which is being used for these tests.

The tests failing were

TypeWriter › should maintain caret position
TypeWriter › should maintain caret position after leaving last editable

I tested both of those using npm run test-e2e packages/e2e-tests/specs/edi tor/various/typewriter.test.js -- --puppeteer-interactive, passing on master but failing on this branch prior to this commit.

My guess is that with the padding as it was, there was enough room on the canvas for the blocks to fit without the typewriter effect setting in. This would explain why simply adding some enter-key presses fixed the test for me.

But it does suggest that this particular test is very sensitive to things style properties like padding, margin, line-height and font size. For example if TwentyTwenty updates the editor style to add this padding back, or to change a block margin, this test will likely fail again. Is there a way to make it more resilient than just adding more blocks? Or conversely, is simply adding more blocks an okay way to fix this test?

@jasmussen
Copy link
Contributor Author

Updated the tests, and merging.

@jasmussen jasmussen merged commit 67f30e1 into master Jun 22, 2020
@jasmussen jasmussen deleted the try/remove-left-right-canvas-padding branch June 22, 2020 09:18
@github-actions github-actions bot added this to the Gutenberg 8.4 milestone Jun 22, 2020
This was referenced Jun 24, 2020
@ockham ockham mentioned this pull request Jun 29, 2020
6 tasks
ockham added a commit that referenced this pull request Jun 29, 2020
This carries over a change that was applied to the Post Editor in #22213.
See there for more context.
ockham added a commit that referenced this pull request Jun 30, 2020
For the Site Editor, we want to allow post content to be inserted at full width (e.g. Cover Blocks). This is currently impossible (see Automattic/wp-calypso#43640) due to two independent problems. This PR fixes them.

1. [Unlike the Post Editor](https://github.com/WordPress/WordPress/blob/f18870ae4e1cb3cd81136424e43c99d705aa2912/wp-admin/edit-form-blocks.php#L286), we're currently not setting `alignWide` in the Site Editor's settings, which becomes a problem here: https://github.com/WordPress/gutenberg/blob/9cd07a92d463377767f56c2b3985badbd363d98f/packages/block-editor/src/hooks/align.js#L173-L196.
2. In order to specifically make the Post Content block full-width, we need to add `align` to its `supports` attribute. (It's still conceivable to use this block at other widths, e.g. in a setting with a sidebar.)

Finally, there remained a 10px padding even after applying these changes. This was fixed by removing block list padding from the Site Editor (a change that had previously been applied to the Post Editor in #22213).
@ellatrix ellatrix mentioned this pull request Oct 27, 2020
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 [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants