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

Verse Block: Add padding control #27579

Closed
wants to merge 9 commits into from
Closed

Conversation

scruffian
Copy link
Contributor

@scruffian scruffian commented Dec 8, 2020

Another attempt at #27341

Description

This reimplements a custom padding control for the verse block. It also includes a couple of other fixes:

This is necessary to address the errors found in the previous PR: #27561

We also need to add custom units to the BoxControl, so we can support other units: #27615

How has this been tested?

In TT1 Blocks

Screenshots

Screenshot 2020-12-08 at 18 56 45

There seems to be an issue with the visualizer component.

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@scruffian scruffian self-assigned this Dec 8, 2020
@github-actions
Copy link

github-actions bot commented Dec 8, 2020

Size Change: +101 B (0%)

Total Size: 1.28 MB

Filename Size Change
build/block-editor/index.js 128 kB +46 B (0%)
build/block-library/blocks/verse/editor-rtl.css 110 B -8 B (7%)
build/block-library/blocks/verse/editor.css 110 B -8 B (7%)
build/block-library/editor-rtl.css 9.06 kB -4 B (0%)
build/block-library/editor.css 9.06 kB -2 B (0%)
build/block-library/index.js 150 kB +57 B (0%)
build/components/index.js 171 kB +20 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.8 kB 0 B
build/api-fetch/index.js 3.42 kB 0 B
build/autop/index.js 2.84 kB 0 B
build/blob/index.js 665 B 0 B
build/block-directory/index.js 8.72 kB 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-editor/style-rtl.css 11.2 kB 0 B
build/block-editor/style.css 11.2 kB 0 B
build/block-library/blocks/archives/editor-rtl.css 120 B 0 B
build/block-library/blocks/archives/editor.css 119 B 0 B
build/block-library/blocks/audio/editor-rtl.css 118 B 0 B
build/block-library/blocks/audio/editor.css 118 B 0 B
build/block-library/blocks/audio/style-rtl.css 152 B 0 B
build/block-library/blocks/audio/style.css 152 B 0 B
build/block-library/blocks/block/editor-rtl.css 211 B 0 B
build/block-library/blocks/block/editor.css 211 B 0 B
build/block-library/blocks/button/editor-rtl.css 513 B 0 B
build/block-library/blocks/button/editor.css 513 B 0 B
build/block-library/blocks/button/style-rtl.css 488 B 0 B
build/block-library/blocks/button/style.css 488 B 0 B
build/block-library/blocks/buttons/editor-rtl.css 275 B 0 B
build/block-library/blocks/buttons/editor.css 275 B 0 B
build/block-library/blocks/buttons/style-rtl.css 346 B 0 B
build/block-library/blocks/buttons/style.css 346 B 0 B
build/block-library/blocks/calendar/style-rtl.css 249 B 0 B
build/block-library/blocks/calendar/style.css 249 B 0 B
build/block-library/blocks/categories/editor-rtl.css 135 B 0 B
build/block-library/blocks/categories/editor.css 135 B 0 B
build/block-library/blocks/categories/style-rtl.css 132 B 0 B
build/block-library/blocks/categories/style.css 132 B 0 B
build/block-library/blocks/code/style-rtl.css 152 B 0 B
build/block-library/blocks/code/style.css 152 B 0 B
build/block-library/blocks/columns/editor-rtl.css 239 B 0 B
build/block-library/blocks/columns/editor.css 239 B 0 B
build/block-library/blocks/columns/style-rtl.css 467 B 0 B
build/block-library/blocks/columns/style.css 466 B 0 B
build/block-library/blocks/cover/editor-rtl.css 440 B 0 B
build/block-library/blocks/cover/editor.css 438 B 0 B
build/block-library/blocks/cover/style-rtl.css 1.27 kB 0 B
build/block-library/blocks/cover/style.css 1.27 kB 0 B
build/block-library/blocks/embed/editor-rtl.css 529 B 0 B
build/block-library/blocks/embed/editor.css 529 B 0 B
build/block-library/blocks/embed/style-rtl.css 419 B 0 B
build/block-library/blocks/embed/style.css 419 B 0 B
build/block-library/blocks/file/editor-rtl.css 246 B 0 B
build/block-library/blocks/file/editor.css 245 B 0 B
build/block-library/blocks/file/style-rtl.css 288 B 0 B
build/block-library/blocks/file/style.css 289 B 0 B
build/block-library/blocks/freeform/editor-rtl.css 2.49 kB 0 B
build/block-library/blocks/freeform/editor.css 2.49 kB 0 B
build/block-library/blocks/gallery/editor-rtl.css 692 B 0 B
build/block-library/blocks/gallery/editor.css 693 B 0 B
build/block-library/blocks/gallery/style-rtl.css 1.11 kB 0 B
build/block-library/blocks/gallery/style.css 1.11 kB 0 B
build/block-library/blocks/group/editor-rtl.css 364 B 0 B
build/block-library/blocks/group/editor.css 364 B 0 B
build/block-library/blocks/group/style-rtl.css 117 B 0 B
build/block-library/blocks/group/style.css 117 B 0 B
build/block-library/blocks/heading/editor-rtl.css 174 B 0 B
build/block-library/blocks/heading/editor.css 174 B 0 B
build/block-library/blocks/heading/style-rtl.css 137 B 0 B
build/block-library/blocks/heading/style.css 137 B 0 B
build/block-library/blocks/html/editor-rtl.css 324 B 0 B
build/block-library/blocks/html/editor.css 325 B 0 B
build/block-library/blocks/image/editor-rtl.css 738 B 0 B
build/block-library/blocks/image/editor.css 737 B 0 B
build/block-library/blocks/image/style-rtl.css 510 B 0 B
build/block-library/blocks/image/style.css 511 B 0 B
build/block-library/blocks/latest-comments/editor-rtl.css 201 B 0 B
build/block-library/blocks/latest-comments/editor.css 200 B 0 B
build/block-library/blocks/latest-comments/style-rtl.css 315 B 0 B
build/block-library/blocks/latest-comments/style.css 315 B 0 B
build/block-library/blocks/latest-posts/editor-rtl.css 183 B 0 B
build/block-library/blocks/latest-posts/editor.css 183 B 0 B
build/block-library/blocks/latest-posts/style-rtl.css 568 B 0 B
build/block-library/blocks/latest-posts/style.css 567 B 0 B
build/block-library/blocks/list/editor-rtl.css 129 B 0 B
build/block-library/blocks/list/editor.css 129 B 0 B
build/block-library/blocks/list/style-rtl.css 127 B 0 B
build/block-library/blocks/list/style.css 127 B 0 B
build/block-library/blocks/media-text/editor-rtl.css 240 B 0 B
build/block-library/blocks/media-text/editor.css 240 B 0 B
build/block-library/blocks/media-text/style-rtl.css 579 B 0 B
build/block-library/blocks/media-text/style.css 577 B 0 B
build/block-library/blocks/more/editor-rtl.css 479 B 0 B
build/block-library/blocks/more/editor.css 479 B 0 B
build/block-library/blocks/navigation-link/editor-rtl.css 438 B 0 B
build/block-library/blocks/navigation-link/editor.css 440 B 0 B
build/block-library/blocks/navigation-link/style-rtl.css 747 B 0 B
build/block-library/blocks/navigation-link/style.css 745 B 0 B
build/block-library/blocks/navigation/editor-rtl.css 1.31 kB 0 B
build/block-library/blocks/navigation/editor.css 1.31 kB 0 B
build/block-library/blocks/navigation/style-rtl.css 222 B 0 B
build/block-library/blocks/navigation/style.css 222 B 0 B
build/block-library/blocks/nextpage/editor-rtl.css 440 B 0 B
build/block-library/blocks/nextpage/editor.css 440 B 0 B
build/block-library/blocks/paragraph/editor-rtl.css 161 B 0 B
build/block-library/blocks/paragraph/editor.css 161 B 0 B
build/block-library/blocks/paragraph/style-rtl.css 279 B 0 B
build/block-library/blocks/paragraph/style.css 279 B 0 B
build/block-library/blocks/post-author/editor-rtl.css 255 B 0 B
build/block-library/blocks/post-author/editor.css 255 B 0 B
build/block-library/blocks/post-author/style-rtl.css 229 B 0 B
build/block-library/blocks/post-author/style.css 230 B 0 B
build/block-library/blocks/post-comments-form/style-rtl.css 293 B 0 B
build/block-library/blocks/post-comments-form/style.css 293 B 0 B
build/block-library/blocks/post-content/editor-rtl.css 187 B 0 B
build/block-library/blocks/post-content/editor.css 187 B 0 B
build/block-library/blocks/post-excerpt/editor-rtl.css 134 B 0 B
build/block-library/blocks/post-excerpt/editor.css 134 B 0 B
build/block-library/blocks/post-featured-image/editor-rtl.css 387 B 0 B
build/block-library/blocks/post-featured-image/editor.css 386 B 0 B
build/block-library/blocks/post-featured-image/style-rtl.css 149 B 0 B
build/block-library/blocks/post-featured-image/style.css 149 B 0 B
build/block-library/blocks/preformatted/style-rtl.css 119 B 0 B
build/block-library/blocks/preformatted/style.css 119 B 0 B
build/block-library/blocks/pullquote/editor-rtl.css 231 B 0 B
build/block-library/blocks/pullquote/editor.css 231 B 0 B
build/block-library/blocks/pullquote/style-rtl.css 359 B 0 B
build/block-library/blocks/pullquote/style.css 359 B 0 B
build/block-library/blocks/query-loop/editor-rtl.css 142 B 0 B
build/block-library/blocks/query-loop/editor.css 141 B 0 B
build/block-library/blocks/query-loop/style-rtl.css 361 B 0 B
build/block-library/blocks/query-loop/style.css 363 B 0 B
build/block-library/blocks/query/editor-rtl.css 179 B 0 B
build/block-library/blocks/query/editor.css 179 B 0 B
build/block-library/blocks/quote/editor-rtl.css 121 B 0 B
build/block-library/blocks/quote/editor.css 121 B 0 B
build/block-library/blocks/quote/style-rtl.css 215 B 0 B
build/block-library/blocks/quote/style.css 214 B 0 B
build/block-library/blocks/rss/editor-rtl.css 270 B 0 B
build/block-library/blocks/rss/editor.css 270 B 0 B
build/block-library/blocks/rss/style-rtl.css 314 B 0 B
build/block-library/blocks/rss/style.css 313 B 0 B
build/block-library/blocks/search/editor-rtl.css 213 B 0 B
build/block-library/blocks/search/editor.css 213 B 0 B
build/block-library/blocks/search/style-rtl.css 384 B 0 B
build/block-library/blocks/search/style.css 386 B 0 B
build/block-library/blocks/separator/editor-rtl.css 151 B 0 B
build/block-library/blocks/separator/editor.css 151 B 0 B
build/block-library/blocks/separator/style-rtl.css 281 B 0 B
build/block-library/blocks/separator/style.css 281 B 0 B
build/block-library/blocks/shortcode/editor-rtl.css 547 B 0 B
build/block-library/blocks/shortcode/editor.css 547 B 0 B
build/block-library/blocks/site-logo/editor-rtl.css 251 B 0 B
build/block-library/blocks/site-logo/editor.css 251 B 0 B
build/block-library/blocks/site-logo/style-rtl.css 166 B 0 B
build/block-library/blocks/site-logo/style.css 166 B 0 B
build/block-library/blocks/social-link/editor-rtl.css 211 B 0 B
build/block-library/blocks/social-link/editor.css 211 B 0 B
build/block-library/blocks/social-links/editor-rtl.css 749 B 0 B
build/block-library/blocks/social-links/editor.css 749 B 0 B
build/block-library/blocks/social-links/style-rtl.css 1.37 kB 0 B
build/block-library/blocks/social-links/style.css 1.37 kB 0 B
build/block-library/blocks/spacer/editor-rtl.css 321 B 0 B
build/block-library/blocks/spacer/editor.css 321 B 0 B
build/block-library/blocks/spacer/style-rtl.css 107 B 0 B
build/block-library/blocks/spacer/style.css 107 B 0 B
build/block-library/blocks/subhead/editor-rtl.css 148 B 0 B
build/block-library/blocks/subhead/editor.css 148 B 0 B
build/block-library/blocks/subhead/style-rtl.css 134 B 0 B
build/block-library/blocks/subhead/style.css 134 B 0 B
build/block-library/blocks/table/editor-rtl.css 530 B 0 B
build/block-library/blocks/table/editor.css 530 B 0 B
build/block-library/blocks/table/style-rtl.css 433 B 0 B
build/block-library/blocks/table/style.css 433 B 0 B
build/block-library/blocks/tag-cloud/editor-rtl.css 162 B 0 B
build/block-library/blocks/tag-cloud/editor.css 162 B 0 B
build/block-library/blocks/tag-cloud/style-rtl.css 145 B 0 B
build/block-library/blocks/tag-cloud/style.css 145 B 0 B
build/block-library/blocks/template-part/editor-rtl.css 644 B 0 B
build/block-library/blocks/template-part/editor.css 645 B 0 B
build/block-library/blocks/text-columns/editor-rtl.css 146 B 0 B
build/block-library/blocks/text-columns/editor.css 146 B 0 B
build/block-library/blocks/text-columns/style-rtl.css 209 B 0 B
build/block-library/blocks/text-columns/style.css 209 B 0 B
build/block-library/blocks/verse/style-rtl.css 137 B 0 B
build/block-library/blocks/verse/style.css 137 B 0 B
build/block-library/blocks/video/editor-rtl.css 547 B 0 B
build/block-library/blocks/video/editor.css 548 B 0 B
build/block-library/blocks/video/style-rtl.css 241 B 0 B
build/block-library/blocks/video/style.css 241 B 0 B
build/block-library/common-rtl.css 940 B 0 B
build/block-library/common.css 937 B 0 B
build/block-library/style-rtl.css 8.48 kB 0 B
build/block-library/style.css 8.48 kB 0 B
build/block-library/theme-rtl.css 789 B 0 B
build/block-library/theme.css 790 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.06 kB 0 B
build/blocks/index.js 48.1 kB 0 B
build/components/style-rtl.css 15.4 kB 0 B
build/components/style.css 15.4 kB 0 B
build/compose/index.js 11 kB 0 B
build/core-data/index.js 15.4 kB 0 B
build/data-controls/index.js 827 B 0 B
build/data/index.js 8.98 kB 0 B
build/date/index.js 31.8 kB 0 B
build/deprecated/index.js 768 B 0 B
build/dom-ready/index.js 571 B 0 B
build/dom/index.js 4.95 kB 0 B
build/edit-navigation/index.js 11.1 kB 0 B
build/edit-navigation/style-rtl.css 881 B 0 B
build/edit-navigation/style.css 885 B 0 B
build/edit-post/index.js 306 kB 0 B
build/edit-post/style-rtl.css 6.47 kB 0 B
build/edit-post/style.css 6.45 kB 0 B
build/edit-site/index.js 24.4 kB 0 B
build/edit-site/style-rtl.css 3.91 kB 0 B
build/edit-site/style.css 3.91 kB 0 B
build/edit-widgets/index.js 26.3 kB 0 B
build/edit-widgets/style-rtl.css 3.1 kB 0 B
build/edit-widgets/style.css 3.1 kB 0 B
build/editor/editor-styles-rtl.css 476 B 0 B
build/editor/editor-styles.css 478 B 0 B
build/editor/index.js 43.3 kB 0 B
build/editor/style-rtl.css 3.84 kB 0 B
build/editor/style.css 3.84 kB 0 B
build/element/index.js 4.63 kB 0 B
build/escape-html/index.js 735 B 0 B
build/format-library/index.js 6.73 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.27 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.57 kB 0 B
build/is-shallow-equal/index.js 698 B 0 B
build/keyboard-shortcuts/index.js 2.54 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.1 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/media-utils/index.js 5.32 kB 0 B
build/notices/index.js 1.86 kB 0 B
build/nux/index.js 3.42 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.54 kB 0 B
build/primitives/index.js 1.43 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.84 kB 0 B
build/reusable-blocks/index.js 2.92 kB 0 B
build/rich-text/index.js 13.4 kB 0 B
build/server-side-render/index.js 2.77 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 2.84 kB 0 B
build/viewport/index.js 1.86 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.22 kB 0 B

compressed-size-action

@scruffian scruffian changed the title Update/verse block padding Verse Block: Add padding control Dec 8, 2020
@scruffian scruffian marked this pull request as ready for review December 8, 2020 18:55
@scruffian scruffian added [Block] Verse Affects the Verse block Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Dec 8, 2020
Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

I have some questions to clarify around new reset functionality.

I need to test this PR later today but in general it looks like an improved version of the previous attempt 👍

packages/block-editor/src/hooks/padding.js Outdated Show resolved Hide resolved
@@ -94,7 +95,7 @@ export default function BoxControl( {
const handleOnReset = () => {
const initialValues = DEFAULT_VALUES;

onChange( initialValues );
onReset();
Copy link
Member

Choose a reason for hiding this comment

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

With this change, when onReset isn't provided it will become noop which is change in the behavior. Should it run all logic instead for backward compatibility?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was kind of tricky, so I changed the reset function to return true so we could see if it's set or not. Let me know if you can think of a better way to do it.

@gziolo
Copy link
Member

gziolo commented Dec 10, 2020

I tested with the following saved post:

<!-- wp:verse -->
<pre class="wp-block-verse">regular verse</pre>
<!-- /wp:verse -->

<!-- wp:verse {"style":{"typography":{"fontFamily":"var:preset|font-family|serif"}}} -->
<pre class="wp-block-verse" style="font-family:var(--wp--preset--font-family--serif)">another paragraph  serif</pre>
<!-- /wp:verse -->

<!-- wp:verse {"textAlign":"center"} -->
<pre class="wp-block-verse has-text-align-center">center aligned verse</pre>
<!-- /wp:verse -->

There is something happening with block validation when text alignment is set:

Screen Shot 2020-12-10 at 10 53 39

@nosolosw and @jorgefilipecosta, it something that is quite concerning. Is there a strategy for how those default styles should be applied to avoid content invalidation?

@jorgefilipecosta
Copy link
Member

jorgefilipecosta commented Dec 10, 2020

I tested with the following saved post:

<!-- wp:verse -->
<pre class="wp-block-verse">regular verse</pre>
<!-- /wp:verse -->

<!-- wp:verse {"style":{"typography":{"fontFamily":"var:preset|font-family|serif"}}} -->
<pre class="wp-block-verse" style="font-family:var(--wp--preset--font-family--serif)">another paragraph  serif</pre>
<!-- /wp:verse -->

<!-- wp:verse {"textAlign":"center"} -->
<pre class="wp-block-verse has-text-align-center">center aligned verse</pre>
<!-- /wp:verse -->

There is something happening with block validation when text alignment is set:

Screen Shot 2020-12-10 at 10 53 39

@nosolosw and @jorgefilipecosta, it something that is quite concerning. Is there a strategy for how those default styles should be applied to avoid content invalidation?

It seems you are getting the validation error because the markup is missing the padding?
If we use:

<!-- wp:verse {"textAlign":"center"} -->
<pre class="wp-block-verse has-text-align-center" style="padding-bottom:20px;padding-left:20px;padding-right:20px;padding-top:20px">sdsdsds
ererere</pre>
<!-- /wp:verse -->

The default styles for a block should be applied using block styles CSS.
In master when I add a verse block I automatically get padding styles applied:

<!-- wp:verse -->
<pre class="wp-block-verse" style="padding-bottom:20px;padding-left:20px;padding-right:20px;padding-top:20px">test</pre>
<!-- /wp:verse -->

This does not seem correct I guess this padding should have been applied on style.scss.

@@ -60,7 +60,7 @@ function mode( arr ) {
* @return {string} A value + unit for the 'all' input.
*/
export function getAllValue( values = {} ) {
const parsedValues = Object.values( values ).map( parseUnit );
const parsedValues = Object.values( values ).map( value => parseUnit( value ) );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a nasty bug - without this line non-pixel units get converted to px

@scruffian
Copy link
Contributor Author

scruffian commented Dec 15, 2020

@jorgefilipecosta @nosolosw @gziolo I think the issue with the validation comes about because of how the text-align: center attribute is added to the inline style property.

To replicate, checkout master, create a verse block and align it center. Then check out this branch. You should see the error Greg mentioned.

This is coming about from a mismatch of the originalContent and generatedContent:

Original content:
<pre class="wp-block-verse has-text-align-center">this is a verse block</pre>

Generated content
<pre style="text-align:center" class="wp-block-verse has-text-align-center">this is a verse block</pre>

From what I can see this isn't directly related to the padding at all. However it seems that by adding the default padding we also generate this inline style on the block which wasn't there before. I've been digging around inside getSaveElement but I'm starting to reach the end of my understanding so if any of you could help debug that would be great. Thank you!

@@ -10,14 +10,29 @@
"default": "",
"__unstablePreserveWhiteSpace": true
},
"style": {
Copy link
Member

Choose a reason for hiding this comment

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

Setting defaults in this way will make sure they are included as inline styles. Doing that will make theme.json not work as expected because theme.json does not produce inline styles but targets using a class. Also including inline styles even if the user does not change anything does not seems like a good idea. As all the verse blocks would have this markup instead of just having a single class with the style rule we would repeat it every time.

Allowing blocks to set default style properties may be a good idea. An equivalent to theme.json that blocks can use to target their own selector. In the future, I guess we should probably consider this. But I guess for now these defaults should just be added as CSS to the style.scss file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

It seems the documentation refers to something that at least for now should not be used. I will propose a PR to remove that from the documentation. Thank you for bringing our attention to this documentation isse.

@jorgefilipecosta
Copy link
Member

@jorgefilipecosta @nosolosw @gziolo I think the issue with the validation comes about because of how the text-align: center attribute is added to the inline style property.

To replicate, checkout master, create a verse block and align it center. Then check out this branch. You should see the error Greg mentioned.

This is coming about from a mismatch of the originalContent and generatedContent:

Original content:

this is a verse block
Generated content

this is a verse block
From what I can see this isn't directly related to the padding at all. However it seems that by adding the default padding we also generate this inline style on the block which wasn't there before. I've been digging around inside getSaveElement but I'm starting to reach the end of my understanding so if any of you could help debug that would be great. Thank you!

The validation issue that happens when we pass markup from master to this branch does not seem related to align but to the fact that we are adding a default style in this branch.
When we add or change a default attribute, we are creating a new version of the block because the markup of the default block state changes, e.g., in this case, we would need to add style attributes to the verse block. So as we do not include deprecation logic, what I expect is that any verse block created in master would become invalid in this branch.

When I create a verse block in this branch, I get the following markup:

<!-- wp:verse -->
<pre class="wp-block-verse" style="padding-bottom:1em;padding-left:1em;padding-right:1em;padding-top:1em">111111</pre>
<!-- /wp:verse -->

On master I get the following markup for each alignment :

<!-- wp:verse -->
<pre class="wp-block-verse">left</pre>
<!-- /wp:verse -->

<!-- wp:verse {"textAlign":"center"} -->
<pre class="wp-block-verse has-text-align-center">center</pre>
<!-- /wp:verse -->

<!-- wp:verse {"textAlign":"right"} -->
<pre class="wp-block-verse has-text-align-right">right</pre>
<!-- /wp:verse -->

If put the markup above from master on this branch the center and right block are considered invalid which is right because they don't have the style markup this branch includes. The left is considered valid, that is the strange part I think should be considered invalid as well.

But regarding these issues, I think we should not add a default style attribute, as besides requiring deprecation logic, there are other cons. I expanded in detail in a comment #27579 (comment) and proposed a possible alternative for now.

@gziolo
Copy link
Member

gziolo commented Dec 17, 2020

It feels like having a way to set the default padding in the block's supports field instead would make it more convenient for customization purposes. In addition to true it could support an object with default values or anything that the theme.json is using.

@scruffian
Copy link
Contributor Author

The problem with setting this in CSS is that when a user resets the control they will expect the padding to return to zero, but it will show the CSS padding, which is super confusing. I created #27796 to track this. I guess this PR is blocked by that one.

@WordPress WordPress locked and limited conversation to collaborators Dec 18, 2020
@WordPress WordPress unlocked this conversation Dec 18, 2020
@jorgefilipecosta
Copy link
Member

The problem with setting this in CSS is that when a user resets the control they will expect the padding to return to zero, but it will show the CSS padding, which is super confusing. I created #27796 to track this. I guess this PR is blocked by that one.

Hi @scruffian,
If padding is set with theme.json the reset would reset to the theme.json. What the reset does is remove the local user customization at the block level, to use whatever value would be used if the user did not change anything for that block. So it seems the reset not using 0 but using the default value in the scss is the expected behavior. The default may come from the block, from a pattern that uses the block, from theme.json, or from user customization in global styles. A reset would clean what is specific for that block if the user wants to remove padding the user would need to set padding to 0.
In a similar way when we reset a font font size we don't make the font size 0 we use whatever value comes from the CSS.
The same for colors when we reset a color we don't remove a color we just use what comes from css.

@jorgefilipecosta
Copy link
Member

I created #27796 to track this. I guess this PR is blocked by that one.

I expanded my thoughts on #27796. I think this PR is not necessarily blocked, we can for now set the padding in the stylesheet and when a block.json style system exists we just remove the styles and use that system.

@scruffian
Copy link
Contributor Author

I see two problems with doing it this way:

  1. It makes it impossible to totally remove the padding - once you set it to zero, the control assumes you don't want to set padding, but then of course the CSS takes over
  2. The user is confused - they see a setting of "0" in the sidebar, but there is evidently padding on the block.

Why not show the default value (either from the block.json, or the theme.json) to the user when they reset the control?

@jorgefilipecosta
Copy link
Member

I see two problems with doing it this way:

  1. It makes it impossible to totally remove the padding - once you set it to zero, the control assumes you don't want to set padding, but then of course the CSS takes over
  2. The user is confused - they see a setting of "0" in the sidebar, but there is evidently padding on the block.

Hi @scruffian, this behaviours seems like a bug where some part of our code assumes padding of 0 (falsy) as undefined and does not apply the padding. If the user applies padding of 0 we should make sure padding of 0 is applied and the input field shows 0. The fact that the control assumes 0 is equal to no padding is something we need to correct.

Why not show the default value (either from the block.json, or the theme.json) to the user when they reset the control?

This is something we want to explore as part of global styles work. And we will probably implement something to address this. But unfortunately, we don't have this yet it will depend on how nesting of semantic styles will work and is something a little bit complex. The default can be from the theme or from the user or some pattern and when we have semantic nesting on theme.json, the same verse block may have a padding of 1em, when on single post view and 0.5em when rendered on the post list so what default would we show for padding at the block level? The specific default of that block instance would depend from the contexts where it is nested.

@scruffian
Copy link
Contributor Author

The specific default of that block instance would depend from the contexts where it is nested.

Yes I agree; I am just saying that we should update the control to reflect this setting, whatever it is. Another option would be to visually disable the control when it's not currently active.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Verse Affects the Verse block Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants