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

Cover block: background element's classname consistency #38392

Merged
merged 10 commits into from
Feb 9, 2022

Conversation

ramonjd
Copy link
Member

@ramonjd ramonjd commented Feb 1, 2022

Description

Following on from conversations in: #38362 (comment)

Here is a Pull Request that updates the classnames on the Cover Block background span element in order to:

  1. Remove duplicated gradientClass where there is no media url
  2. Add a permanent classname to the background <span /> of wp-block-cover__background to replace wp-block-cover__gradient-background, since the former latter applied to the element all the time (even where there is no gradient)
  3. Revert the addition of wp-block-cover__gradient-background to the logic before the the change in October 2021
  4. Achieve World Peace ☮️

So, in the save.js, the element is switching from:

				<span
					aria-hidden="true"
					className={ classnames(
						overlayColorClass,
						dimRatioToClass( dimRatio ),
						'wp-block-cover__gradient-background',
						gradientClass,
						{
							'has-background-dim': dimRatio !== undefined,
							'has-background-gradient':
								gradient || customGradient,
							[ gradientClass ]: ! url && gradientClass,
						}
					) }
					style={ bgStyle }
				/>

To:

			<span
				aria-hidden="true"
				className={ classnames(
					'wp-block-cover__background',
					overlayColorClass,
					dimRatioToClass( dimRatio ),
					{
						'has-background-dim': dimRatio !== undefined,
						// For backwards compatibility. Former versions of the Cover Block applied
						// `.wp-block-cover__gradient-background` in the presence of
						// media, a gradient and a dim.
						'wp-block-cover__gradient-background':
							url && gradientValue && dimRatio !== 0,
						'has-background-gradient': gradientValue,
						[ gradientClass ]: gradientClass,
					}
				) }
				style={ bgStyle }
			/>

We've added an extra deprecation and updated the fixtures and other tests.

Testing Instructions

Here are some test blocks created using trunk. Paste them in the code view of the block editor and ensure that there are no validation errors.

Test blocks
<!-- wp:cover {"url":"http://localhost:4759/wp-content/uploads/2022/01/puppy.jpg","id":216,"dimRatio":50,"isDark":false} -->
<div class="wp-block-cover is-light"><span aria-hidden="true" class="wp-block-cover__gradient-background has-background-dim"></span><img class="wp-block-cover__image-background wp-image-216" alt="" src="http://localhost:4759/wp-content/uploads/2022/01/puppy.jpg" data-object-fit="cover"/><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Cover block with image and dim</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

<!-- wp:cover {"url":"http://localhost:4759/wp-content/uploads/2022/01/how-to-grow-organic-fiddlehead-ferns-2539638-hero-23c689cdd2b74f0c9e817cc6e710f0b8-scaled.jpg","id":213,"dimRatio":0,"gradient":"pale-ocean"} -->
<div class="wp-block-cover"><span aria-hidden="true" class="has-background-dim-0 wp-block-cover__gradient-background has-pale-ocean-gradient-background has-background-dim has-background-gradient"></span><img class="wp-block-cover__image-background wp-image-213" alt="" src="http://localhost:4759/wp-content/uploads/2022/01/how-to-grow-organic-fiddlehead-ferns-2539638-hero-23c689cdd2b74f0c9e817cc6e710f0b8-scaled.jpg" data-object-fit="cover"/><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Cover block with image, gradient and no dim</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

<!-- wp:cover {"url":"http://localhost:4759/wp-content/uploads/2022/01/how-to-grow-organic-fiddlehead-ferns-2539638-hero-23c689cdd2b74f0c9e817cc6e710f0b8-scaled.jpg","id":213,"dimRatio":80,"gradient":"cool-to-warm-spectrum"} -->
<div class="wp-block-cover"><span aria-hidden="true" class="has-background-dim-80 wp-block-cover__gradient-background has-cool-to-warm-spectrum-gradient-background has-background-dim has-background-gradient"></span><img class="wp-block-cover__image-background wp-image-213" alt="" src="http://localhost:4759/wp-content/uploads/2022/01/how-to-grow-organic-fiddlehead-ferns-2539638-hero-23c689cdd2b74f0c9e817cc6e710f0b8-scaled.jpg" data-object-fit="cover"/><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Cover block with image, dim, and custom gradient</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

<!-- wp:cover {"overlayColor":"highlight","isDark":false} -->
<div class="wp-block-cover is-light"><span aria-hidden="true" class="has-highlight-background-color has-background-dim-100 wp-block-cover__gradient-background has-background-dim"></span><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Cover block with plain background</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

<!-- wp:cover {"gradient":"luminous-dusk","isDark":false} -->
<div class="wp-block-cover is-light"><span aria-hidden="true" class="has-background-dim-100 wp-block-cover__gradient-background has-luminous-dusk-gradient-background has-background-dim has-background-gradient has-luminous-dusk-gradient-background"></span><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Cover block with gradient background</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

Types of changes

Block classname changes and deprecation

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • 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 (please manually search all *.native.js files for terms that need renaming or removal).
  • I've updated related schemas if appropriate.

@ramonjd
Copy link
Member Author

ramonjd commented Feb 1, 2022

Fixtures won't pass because the deprecation can't yet handle the classname changes 🤷

@github-actions
Copy link

github-actions bot commented Feb 1, 2022

Size Change: +2.81 kB (0%)

Total Size: 1.14 MB

Filename Size Change
build/block-editor/index.min.js 141 kB +68 B (0%)
build/block-library/blocks/cover/style-rtl.css 1.55 kB +155 B (+11%) ⚠️
build/block-library/blocks/cover/style.css 1.55 kB +155 B (+11%) ⚠️
build/block-library/blocks/image/style-rtl.css 500 B -7 B (-1%)
build/block-library/blocks/image/style.css 503 B -8 B (-2%)
build/block-library/blocks/navigation/editor-rtl.css 1.98 kB +61 B (+3%)
build/block-library/blocks/navigation/editor.css 1.99 kB +60 B (+3%)
build/block-library/common-rtl.css 921 B +13 B (+1%)
build/block-library/common.css 919 B +14 B (+2%)
build/block-library/editor-rtl.css 10.1 kB +49 B (0%)
build/block-library/editor.css 10.1 kB +48 B (0%)
build/block-library/index.min.js 167 kB +1.05 kB (+1%)
build/block-library/style-rtl.css 11.3 kB +251 B (+2%)
build/block-library/style.css 11.3 kB +246 B (+2%)
build/components/index.min.js 215 kB +108 B (0%)
build/components/style-rtl.css 15.5 kB +22 B (0%)
build/components/style.css 15.5 kB +20 B (0%)
build/data/index.min.js 7.44 kB -48 B (-1%)
build/edit-post/index.min.js 29.7 kB +138 B (0%)
build/edit-site/index.min.js 41.6 kB +128 B (0%)
build/edit-widgets/index.min.js 16.7 kB +65 B (0%)
build/editor/index.min.js 38.5 kB +108 B (0%)
build/nux/index.min.js 2.09 kB +9 B (0%)
build/plugins/index.min.js 1.95 kB +107 B (+6%) 🔍
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 960 B
build/admin-manifest/index.min.js 1.1 kB
build/annotations/index.min.js 2.75 kB
build/api-fetch/index.min.js 2.22 kB
build/autop/index.min.js 2.12 kB
build/blob/index.min.js 459 B
build/block-directory/index.min.js 6.28 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 kB
build/block-editor/default-editor-styles-rtl.css 378 B
build/block-editor/default-editor-styles.css 378 B
build/block-editor/style-rtl.css 14.6 kB
build/block-editor/style.css 14.6 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 65 B
build/block-library/blocks/archives/style.css 65 B
build/block-library/blocks/audio/editor-rtl.css 150 B
build/block-library/blocks/audio/editor.css 150 B
build/block-library/blocks/audio/style-rtl.css 111 B
build/block-library/blocks/audio/style.css 111 B
build/block-library/blocks/audio/theme-rtl.css 125 B
build/block-library/blocks/audio/theme.css 125 B
build/block-library/blocks/block/editor-rtl.css 161 B
build/block-library/blocks/block/editor.css 161 B
build/block-library/blocks/button/editor-rtl.css 470 B
build/block-library/blocks/button/editor.css 470 B
build/block-library/blocks/button/style-rtl.css 560 B
build/block-library/blocks/button/style.css 560 B
build/block-library/blocks/buttons/editor-rtl.css 292 B
build/block-library/blocks/buttons/editor.css 292 B
build/block-library/blocks/buttons/style-rtl.css 275 B
build/block-library/blocks/buttons/style.css 275 B
build/block-library/blocks/calendar/style-rtl.css 207 B
build/block-library/blocks/calendar/style.css 207 B
build/block-library/blocks/categories/editor-rtl.css 84 B
build/block-library/blocks/categories/editor.css 83 B
build/block-library/blocks/categories/style-rtl.css 79 B
build/block-library/blocks/categories/style.css 79 B
build/block-library/blocks/code/style-rtl.css 90 B
build/block-library/blocks/code/style.css 90 B
build/block-library/blocks/code/theme-rtl.css 131 B
build/block-library/blocks/code/theme.css 131 B
build/block-library/blocks/columns/editor-rtl.css 108 B
build/block-library/blocks/columns/editor.css 108 B
build/block-library/blocks/columns/style-rtl.css 406 B
build/block-library/blocks/columns/style.css 406 B
build/block-library/blocks/comment-template/style-rtl.css 127 B
build/block-library/blocks/comment-template/style.css 127 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 123 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 222 B
build/block-library/blocks/comments-pagination/editor.css 209 B
build/block-library/blocks/comments-pagination/style-rtl.css 235 B
build/block-library/blocks/comments-pagination/style.css 231 B
build/block-library/blocks/comments-query-loop/editor-rtl.css 95 B
build/block-library/blocks/comments-query-loop/editor.css 95 B
build/block-library/blocks/cover/editor-rtl.css 546 B
build/block-library/blocks/cover/editor.css 547 B
build/block-library/blocks/embed/editor-rtl.css 293 B
build/block-library/blocks/embed/editor.css 293 B
build/block-library/blocks/embed/style-rtl.css 417 B
build/block-library/blocks/embed/style.css 417 B
build/block-library/blocks/embed/theme-rtl.css 124 B
build/block-library/blocks/embed/theme.css 124 B
build/block-library/blocks/file/editor-rtl.css 300 B
build/block-library/blocks/file/editor.css 300 B
build/block-library/blocks/file/style-rtl.css 255 B
build/block-library/blocks/file/style.css 255 B
build/block-library/blocks/file/view.min.js 322 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB
build/block-library/blocks/freeform/editor.css 2.44 kB
build/block-library/blocks/gallery/editor-rtl.css 965 B
build/block-library/blocks/gallery/editor.css 967 B
build/block-library/blocks/gallery/style-rtl.css 1.61 kB
build/block-library/blocks/gallery/style.css 1.61 kB
build/block-library/blocks/gallery/theme-rtl.css 122 B
build/block-library/blocks/gallery/theme.css 122 B
build/block-library/blocks/group/editor-rtl.css 159 B
build/block-library/blocks/group/editor.css 159 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 114 B
build/block-library/blocks/heading/style.css 114 B
build/block-library/blocks/html/editor-rtl.css 332 B
build/block-library/blocks/html/editor.css 333 B
build/block-library/blocks/image/editor-rtl.css 810 B
build/block-library/blocks/image/editor.css 809 B
build/block-library/blocks/image/theme-rtl.css 124 B
build/block-library/blocks/image/theme.css 124 B
build/block-library/blocks/latest-comments/style-rtl.css 284 B
build/block-library/blocks/latest-comments/style.css 284 B
build/block-library/blocks/latest-posts/editor-rtl.css 199 B
build/block-library/blocks/latest-posts/editor.css 198 B
build/block-library/blocks/latest-posts/style-rtl.css 447 B
build/block-library/blocks/latest-posts/style.css 446 B
build/block-library/blocks/list/style-rtl.css 94 B
build/block-library/blocks/list/style.css 94 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 493 B
build/block-library/blocks/media-text/style.css 490 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 649 B
build/block-library/blocks/navigation-link/editor.css 650 B
build/block-library/blocks/navigation-link/style-rtl.css 94 B
build/block-library/blocks/navigation-link/style.css 94 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 299 B
build/block-library/blocks/navigation-submenu/editor.css 299 B
build/block-library/blocks/navigation-submenu/view.min.js 343 B
build/block-library/blocks/navigation/style-rtl.css 1.85 kB
build/block-library/blocks/navigation/style.css 1.84 kB
build/block-library/blocks/navigation/view.min.js 2.81 kB
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 401 B
build/block-library/blocks/page-list/editor.css 402 B
build/block-library/blocks/page-list/style-rtl.css 175 B
build/block-library/blocks/page-list/style.css 175 B
build/block-library/blocks/paragraph/editor-rtl.css 157 B
build/block-library/blocks/paragraph/editor.css 157 B
build/block-library/blocks/paragraph/style-rtl.css 273 B
build/block-library/blocks/paragraph/style.css 273 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/style-rtl.css 446 B
build/block-library/blocks/post-comments-form/style.css 446 B
build/block-library/blocks/post-comments/style-rtl.css 521 B
build/block-library/blocks/post-comments/style.css 521 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B
build/block-library/blocks/post-excerpt/editor.css 73 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B
build/block-library/blocks/post-excerpt/style.css 69 B
build/block-library/blocks/post-featured-image/editor-rtl.css 721 B
build/block-library/blocks/post-featured-image/editor.css 721 B
build/block-library/blocks/post-featured-image/style-rtl.css 153 B
build/block-library/blocks/post-featured-image/style.css 153 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 323 B
build/block-library/blocks/post-template/style.css 323 B
build/block-library/blocks/post-terms/style-rtl.css 73 B
build/block-library/blocks/post-terms/style.css 73 B
build/block-library/blocks/post-title/style-rtl.css 80 B
build/block-library/blocks/post-title/style.css 80 B
build/block-library/blocks/preformatted/style-rtl.css 103 B
build/block-library/blocks/preformatted/style.css 103 B
build/block-library/blocks/pullquote/editor-rtl.css 198 B
build/block-library/blocks/pullquote/editor.css 198 B
build/block-library/blocks/pullquote/style-rtl.css 389 B
build/block-library/blocks/pullquote/style.css 388 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 221 B
build/block-library/blocks/query-pagination/editor.css 211 B
build/block-library/blocks/query-pagination/style-rtl.css 234 B
build/block-library/blocks/query-pagination/style.css 231 B
build/block-library/blocks/query/editor-rtl.css 131 B
build/block-library/blocks/query/editor.css 132 B
build/block-library/blocks/quote/style-rtl.css 201 B
build/block-library/blocks/quote/style.css 201 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/read-more/style-rtl.css 132 B
build/block-library/blocks/read-more/style.css 132 B
build/block-library/blocks/rss/editor-rtl.css 202 B
build/block-library/blocks/rss/editor.css 204 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 165 B
build/block-library/blocks/search/editor.css 165 B
build/block-library/blocks/search/style-rtl.css 397 B
build/block-library/blocks/search/style.css 398 B
build/block-library/blocks/search/theme-rtl.css 64 B
build/block-library/blocks/search/theme.css 64 B
build/block-library/blocks/separator/editor-rtl.css 99 B
build/block-library/blocks/separator/editor.css 99 B
build/block-library/blocks/separator/style-rtl.css 245 B
build/block-library/blocks/separator/style.css 245 B
build/block-library/blocks/separator/theme-rtl.css 172 B
build/block-library/blocks/separator/theme.css 172 B
build/block-library/blocks/shortcode/editor-rtl.css 474 B
build/block-library/blocks/shortcode/editor.css 474 B
build/block-library/blocks/site-logo/editor-rtl.css 744 B
build/block-library/blocks/site-logo/editor.css 744 B
build/block-library/blocks/site-logo/style-rtl.css 181 B
build/block-library/blocks/site-logo/style.css 181 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 84 B
build/block-library/blocks/site-title/editor.css 84 B
build/block-library/blocks/social-link/editor-rtl.css 177 B
build/block-library/blocks/social-link/editor.css 177 B
build/block-library/blocks/social-links/editor-rtl.css 674 B
build/block-library/blocks/social-links/editor.css 673 B
build/block-library/blocks/social-links/style-rtl.css 1.37 kB
build/block-library/blocks/social-links/style.css 1.36 kB
build/block-library/blocks/spacer/editor-rtl.css 332 B
build/block-library/blocks/spacer/editor.css 332 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 471 B
build/block-library/blocks/table/editor.css 472 B
build/block-library/blocks/table/style-rtl.css 481 B
build/block-library/blocks/table/style.css 481 B
build/block-library/blocks/table/theme-rtl.css 188 B
build/block-library/blocks/table/theme.css 188 B
build/block-library/blocks/tag-cloud/style-rtl.css 214 B
build/block-library/blocks/tag-cloud/style.css 215 B
build/block-library/blocks/template-part/editor-rtl.css 560 B
build/block-library/blocks/template-part/editor.css 559 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 87 B
build/block-library/blocks/verse/style.css 87 B
build/block-library/blocks/video/editor-rtl.css 571 B
build/block-library/blocks/video/editor.css 572 B
build/block-library/blocks/video/style-rtl.css 173 B
build/block-library/blocks/video/style.css 173 B
build/block-library/blocks/video/theme-rtl.css 124 B
build/block-library/blocks/video/theme.css 124 B
build/block-library/reset-rtl.css 474 B
build/block-library/reset.css 474 B
build/block-library/theme-rtl.css 672 B
build/block-library/theme.css 676 B
build/block-serialization-default-parser/index.min.js 1.09 kB
build/block-serialization-spec-parser/index.min.js 2.79 kB
build/blocks/index.min.js 46.4 kB
build/compose/index.min.js 11.2 kB
build/core-data/index.min.js 13.4 kB
build/customize-widgets/index.min.js 11.4 kB
build/customize-widgets/style-rtl.css 1.5 kB
build/customize-widgets/style.css 1.49 kB
build/data-controls/index.min.js 631 B
build/date/index.min.js 31.9 kB
build/deprecated/index.min.js 485 B
build/dom-ready/index.min.js 304 B
build/dom/index.min.js 4.5 kB
build/edit-navigation/index.min.js 16.2 kB
build/edit-navigation/style-rtl.css 3.76 kB
build/edit-navigation/style.css 3.76 kB
build/edit-post/classic-rtl.css 546 B
build/edit-post/classic.css 547 B
build/edit-post/style-rtl.css 7.15 kB
build/edit-post/style.css 7.14 kB
build/edit-site/style-rtl.css 7.22 kB
build/edit-site/style.css 7.21 kB
build/edit-widgets/style-rtl.css 4.17 kB
build/edit-widgets/style.css 4.17 kB
build/editor/style-rtl.css 3.71 kB
build/editor/style.css 3.71 kB
build/element/index.min.js 3.29 kB
build/escape-html/index.min.js 517 B
build/format-library/index.min.js 6.58 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.63 kB
build/html-entities/index.min.js 424 B
build/i18n/index.min.js 3.75 kB
build/is-shallow-equal/index.min.js 501 B
build/keyboard-shortcuts/index.min.js 1.8 kB
build/keycodes/index.min.js 1.39 kB
build/list-reusable-blocks/index.min.js 1.72 kB
build/list-reusable-blocks/style-rtl.css 838 B
build/list-reusable-blocks/style.css 838 B
build/media-utils/index.min.js 2.92 kB
build/notices/index.min.js 925 B
build/nux/style-rtl.css 747 B
build/nux/style.css 743 B
build/primitives/index.min.js 917 B
build/priority-queue/index.min.js 582 B
build/react-i18n/index.min.js 671 B
build/react-refresh-entry/index.min.js 8.44 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/redux-routine/index.min.js 2.65 kB
build/reusable-blocks/index.min.js 2.22 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 11 kB
build/server-side-render/index.min.js 1.58 kB
build/shortcode/index.min.js 1.49 kB
build/token-list/index.min.js 639 B
build/url/index.min.js 1.9 kB
build/viewport/index.min.js 1.05 kB
build/warning/index.min.js 248 B
build/widgets/index.min.js 7.15 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.04 kB

compressed-size-action

@glendaviesnz
Copy link
Contributor

@ramonjd I think the issue was you had included ...blockAttributes which has a default dimRatio of 50 - but latest default is dimRation of 100 - have pushed a change to this and it now seems to work as expected.

@ramonjd
Copy link
Member Author

ramonjd commented Feb 2, 2022

I think the issue was you had included ...blockAttributes which has a default dimRatio of 50 - but latest default is dimRation of 100 - have pushed a change to this and it now seems to work as expected.

❤️ Thank you! I was staring at this file for eons trying to work out the issue.

@ramonjd ramonjd self-assigned this Feb 2, 2022
@ramonjd ramonjd added [Block] Cover Affects the Cover Block - used to display content laid over a background image [Type] Code Quality Issues or PRs that relate to code quality labels Feb 2, 2022
@ramonjd ramonjd marked this pull request as ready for review February 2, 2022 02:09
@ramonjd ramonjd requested a review from ajitbohra as a code owner February 2, 2022 02:09
@ramonjd ramonjd changed the title Update/cover block background classname Cover block: background element's classname consistency Feb 2, 2022
@ramonjd ramonjd requested review from nerrad and ntwb as code owners February 2, 2022 02:35
ramonjd and others added 7 commits February 2, 2022 13:35
renaming `wp-block-cover__gradient-background` to `wp-block-cover__background` given that the former class is applied regardless of whether there's a gradient.
Removing duplicate gradientClass
@ramonjd ramonjd force-pushed the update/cover-block-background-classname branch from f193def to 99547c4 Compare February 2, 2022 02:37
@ramonjd ramonjd removed request for ntwb and nerrad February 2, 2022 02:38
@carolinan
Copy link
Contributor

There are 4 plugins
and 37 themes in the official directories that uses the
wp-block-cover__gradient-background class.

And possibly any block pattern in the block pattern directory that uses cover blocks.

That is fewer than I would have guessed, but do the developers need to take any action?
Twenty Twenty-Two only uses it as part of a block pattern, and does not add any extra styling using the class. The deprecation will make sure that there are no block validation errors, correct?

@ramonjd
Copy link
Member Author

ramonjd commented Feb 2, 2022

Thanks a lot for the ping @carolinan, and for highlighting the potential effect on existing themes and plugins.

That is fewer than I would have guessed, but do the developers need to take any action?

Before the change in October 2021, which made the class a permanent citizen of the Cover Block markup, the logic to display an element with the classname .wp-block-cover__gradient-background was:

url && gradientValue && dimRatio !== 0

So before October, .wp-block-cover__gradient-background would only be rendered where a Cover Block had media, a gradient and a dim.

We could, and probably should, reinstate the class for this particular scenario, which would mean that only those who have changed their code to rely exclusively on the permanence of this class in the last 3 months would have to take action.

What do you think?

Looking at a lot of existing usage, I think this would be a reasonable mitigation against backwards incompatibility.

We're also keeping the class rules for .wp-block-cover__gradient-background in the Cover Block styles as well.

The only, minor downside is that we're left with a redundant class. No biggie.

A couple of action points for me:

  • Test the Cover Block using some of the plugins and themes you've cited
  • Reinstate the .wp-block-cover__gradient-background class where it would have formerly displayed (rather than all the time)

Also cc @glendaviesnz for thoughts.

The deprecation will make sure that there are no block validation errors, correct?

Yes! All manual and integration tests indicate that it's working as expected 👍

@glendaviesnz
Copy link
Contributor

glendaviesnz commented Feb 2, 2022

We could, and probably should, reinstate the class for this particular scenario, which would mean that only those who have changed their code to rely exclusively on the permanence of this class in the last 3 months would have to take action.

Yes, my thinking is that the majority of usages will be expecting that class to only be in place if there is a gradient applied. I expect that the number of plugins/styles that have added that selector in the last 3 months on the expectation that it is always there will be 0, so reverting it back to only being applied when relevant should prevent more issues than it causes - in theory ... but in theory the Titanic was unsinkable 😄

…had media, a gradient and a dim for backwards compatibility. See #38392#issuecomment-1028434423
@ramonjd
Copy link
Member Author

ramonjd commented Feb 3, 2022

es, my thinking is that the majority of usages will be expecting that class to only be in place if there is a gradient applied. I expect that the number of plugins/styles that have added that selector in the last 3 months on the expectation that it is always there will be 0, so reverting it back to only being applied when relevant should prevent more issues than it causes - in theory ... but in theory the Titanic was unsinkable

I've tested with a few themes and plugins, and looked at usages.

Most are using .wp-block-cover__gradient-background according the previous logic, that is, where the Cover Block has an image, has a background dim and a gradient.

Leaving .wp-block-cover__gradient-background in styles.scss for backwards compatibility takes care of the rest it seems.

But it might be worth doing a shout out on the make blog for anyone who, in the last three months, is relying on that class for other purposes, for example as a general, always-there, selector.

@glendaviesnz
Copy link
Contributor

@ramonjd I wonder if in changing wp-block-cover__gradient-background for wp-block-cover__background we are creating work for theme and plugin authors, ie. the deprecated CSS covers unedited blocks, and migration makes the block compliant with the new core CSS for the block, but theme/plugin author will still potentially need to make changes to support the new class if they are currently using the wp-block-cover__gradient-background class to apply custom CSS?

If we just revert to applying when wp-block-cover__gradient-background when url && gradientValue && dimRatio !== 0 then in theory they shouldn't need to make any changes - but I might be misunderstanding something about this approach?

@ramonjd
Copy link
Member Author

ramonjd commented Feb 7, 2022

If we just revert to applying when wp-block-cover__gradient-background when url && gradientValue && dimRatio !== 0 then in theory they shouldn't need to make any changes

Yeah fair question, thanks.

I originally added the new class .wp-block-cover__background so there'd be a full-time consistent hook for that element.

But I guess nothing is stopping folks from doing something like .wp-block-cover > span

We've already reverted to applying .wp-block-cover__gradient-background under the original conditions: https://github.com/WordPress/gutenberg/pull/38392/files#diff-c9b6422f332979151b7228eb2af812e84859338e6b4d5ef38e5341ef6e8f5a39R737

but theme/plugin author will still potentially need to make changes to support the new class if they are currently using the wp-block-cover__gradient-background class to apply custom CSS?

The only risk scenario I saw is if the theme authors are relying on the persistency of .wp-block-cover__gradient-background since the change in October 2021.

That's the "regression" we had to have in my mind.

I guess leaving out .wp-block-cover__background now won't hurt. Introducing new stuff that we might not need is probably not required right now.

What do you reckon?

@glendaviesnz
Copy link
Contributor

@ramonjd Sorry, I was looking at the code sample in the PR description, which shows wp-block-cover__gradient-background being gone completely, rather than the actual code - will take a better look at it based on what is actually happening 😄

@glendaviesnz
Copy link
Contributor

Seems to be something not quite right with opacity when only background color set. The block on the left is from latest GB but running on frontend with this PR with no migration run. The one on right is from this PR once the migration has run:
Screen Shot 2022-02-08 at 2 34 47 PM

block code is:

<!-- wp:cover {"overlayColor":"vivid-red"} -->
<div class="wp-block-cover has-vivid-red-background-color has-background-dim"><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">BG Color only</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

<!-- wp:cover {"overlayColor":"vivid-red"} -->
<div class="wp-block-cover"><span aria-hidden="true" class="has-vivid-red-background-color has-background-dim-100 wp-block-cover__gradient-background has-background-dim"></span><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">BG Color only</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

Will take a closer look and see if I can work out what is going on here.

@ramonjd
Copy link
Member Author

ramonjd commented Feb 8, 2022

Seems to be something not quite right with opacity when only background color set.

Oooh, thanks for spotting. Maybe a CSS calamity. I see the opacity: 0.5; is being applied.

@glendaviesnz
Copy link
Contributor

Oooh, thanks for spotting. Maybe a CSS calamity. I see the opacity: 0.5; is being applied.

For some reason this is not being applied, but can't see the reason why for looking!

@ramonjd
Copy link
Member Author

ramonjd commented Feb 8, 2022

Edit: Oh... one of these classnames doesn't belong 😆

I think I was missing .wp-block-cover__background here:

	@for $i from 1 through 10 {
		&.has-background-dim.has-background-dim-#{ $i * 10 } {
			&:not(.has-background-gradient)::before,
			.wp-block-cover__background,
			.wp-block-cover__gradient-background {
				opacity: $i * 0.1;
			}
		}
	}

Copy link
Contributor

@glendaviesnz glendaviesnz left a comment

Choose a reason for hiding this comment

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

LGTM. I tested with a whole range of options:

Non-migrated blocks viewed in frontend with this PR
<!-- wp:cover {"overlayColor":"secondary","isDark":false} -->
<div class="wp-block-cover is-light"><span aria-hidden="true" class="has-secondary-background-color has-background-dim-100 wp-block-cover__gradient-background has-background-dim"></span><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Just a color</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

<!-- wp:cover {"gradient":"cool-to-warm-spectrum","isDark":false} -->
<div class="wp-block-cover is-light"><span aria-hidden="true" class="has-background-dim-100 wp-block-cover__gradient-background has-cool-to-warm-spectrum-gradient-background has-background-dim has-background-gradient has-cool-to-warm-spectrum-gradient-background"></span><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Just a gradient</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

<!-- wp:cover {"url":"http://localhost:4759/wp-content/uploads/2022/02/tree2-7.jpeg","id":82,"dimRatio":50} -->
<div class="wp-block-cover"><span aria-hidden="true" class="wp-block-cover__gradient-background has-background-dim"></span><img class="wp-block-cover__image-background wp-image-82" alt="" src="http://localhost:4759/wp-content/uploads/2022/02/tree2-7.jpeg" data-object-fit="cover"/><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Just an image</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

<!-- wp:cover {"dimRatio":30,"overlayColor":"secondary","isDark":false} -->
<div class="wp-block-cover is-light"><span aria-hidden="true" class="has-secondary-background-color has-background-dim-30 wp-block-cover__gradient-background has-background-dim"></span><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Just a color with custom opacity</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

<!-- wp:cover {"dimRatio":60,"gradient":"cool-to-warm-spectrum","isDark":false} -->
<div class="wp-block-cover is-light"><span aria-hidden="true" class="has-background-dim-60 wp-block-cover__gradient-background has-cool-to-warm-spectrum-gradient-background has-background-dim has-background-gradient has-cool-to-warm-spectrum-gradient-background"></span><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Just Gradient with custom opacity</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

<!-- wp:cover {"url":"http://localhost:4759/wp-content/uploads/2022/02/tree2-7.jpeg","id":82,"dimRatio":30} -->
<div class="wp-block-cover"><span aria-hidden="true" class="has-background-dim-30 wp-block-cover__gradient-background has-background-dim"></span><img class="wp-block-cover__image-background wp-image-82" alt="" src="http://localhost:4759/wp-content/uploads/2022/02/tree2-7.jpeg" data-object-fit="cover"/><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Image with custom opacity</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

<!-- wp:cover {"url":"http://localhost:4759/wp-content/uploads/2022/02/tree2-7.jpeg","id":82,"dimRatio":70,"overlayColor":"secondary","isDark":false} -->
<div class="wp-block-cover is-light"><span aria-hidden="true" class="has-secondary-background-color has-background-dim-70 wp-block-cover__gradient-background has-background-dim"></span><img class="wp-block-cover__image-background wp-image-82" alt="" src="http://localhost:4759/wp-content/uploads/2022/02/tree2-7.jpeg" data-object-fit="cover"/><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Image with color and custom opacity</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

<!-- wp:cover {"url":"http://localhost:4759/wp-content/uploads/2022/02/tree2-7.jpeg","id":82,"dimRatio":70,"gradient":"cool-to-warm-spectrum"} -->
<div class="wp-block-cover"><span aria-hidden="true" class="has-background-dim-70 wp-block-cover__gradient-background has-cool-to-warm-spectrum-gradient-background has-background-dim has-background-gradient"></span><img class="wp-block-cover__image-background wp-image-82" alt="" src="http://localhost:4759/wp-content/uploads/2022/02/tree2-7.jpeg" data-object-fit="cover"/><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Image with gradient and custom opacity</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

<!-- wp:cover {"dimRatio":70,"customOverlayColor":"#df6e03","isDark":false} -->
<div class="wp-block-cover is-light"><span aria-hidden="true" class="has-background-dim-70 wp-block-cover__gradient-background has-background-dim" style="background-color:#df6e03"></span><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Custom color and custom opacity</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

<!-- wp:cover {"dimRatio":20,"customGradient":"linear-gradient(135deg,rgb(6,147,227) 0%,rgb(229,2,2) 31%,rgb(155,81,224) 100%)","isDark":false} -->
<div class="wp-block-cover is-light"><span aria-hidden="true" class="has-background-dim-20 wp-block-cover__gradient-background has-background-dim has-background-gradient" style="background:linear-gradient(135deg,rgb(6,147,227) 0%,rgb(229,2,2) 31%,rgb(155,81,224) 100%)"></span><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Custom gradient and custom opacity</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->
New blocks added via editor with this PR
<!-- wp:cover {"overlayColor":"secondary","isDark":false} -->
<div class="wp-block-cover is-light"><span aria-hidden="true" class="wp-block-cover__background has-secondary-background-color has-background-dim-100 has-background-dim"></span><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Just a color</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

<!-- wp:cover {"gradient":"cool-to-warm-spectrum","isDark":false} -->
<div class="wp-block-cover is-light"><span aria-hidden="true" class="wp-block-cover__background has-background-dim-100 has-background-dim has-background-gradient has-cool-to-warm-spectrum-gradient-background"></span><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Just a gradient</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

<!-- wp:cover {"url":"http://localhost:4759/wp-content/uploads/2022/02/tree2-7.jpeg","id":82,"dimRatio":50} -->
<div class="wp-block-cover"><span aria-hidden="true" class="wp-block-cover__background has-background-dim"></span><img class="wp-block-cover__image-background wp-image-82" alt="" src="http://localhost:4759/wp-content/uploads/2022/02/tree2-7.jpeg" data-object-fit="cover"/><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Just an image</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

<!-- wp:cover {"url":"http://localhost:4759/wp-content/uploads/2022/02/tree2-7.jpeg","id":82,"dimRatio":30,"overlayColor":"secondary"} -->
<div class="wp-block-cover"><span aria-hidden="true" class="wp-block-cover__background has-secondary-background-color has-background-dim-30 has-background-dim"></span><img class="wp-block-cover__image-background wp-image-82" alt="" src="http://localhost:4759/wp-content/uploads/2022/02/tree2-7.jpeg" data-object-fit="cover"/><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Image with color and custom opacity</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

<!-- wp:cover {"url":"http://localhost:4759/wp-content/uploads/2022/02/tree2-7.jpeg","id":82,"dimRatio":70,"gradient":"cool-to-warm-spectrum"} -->
<div class="wp-block-cover"><span aria-hidden="true" class="wp-block-cover__background has-background-dim-70 has-background-dim wp-block-cover__gradient-background has-background-gradient has-cool-to-warm-spectrum-gradient-background"></span><img class="wp-block-cover__image-background wp-image-82" alt="" src="http://localhost:4759/wp-content/uploads/2022/02/tree2-7.jpeg" data-object-fit="cover"/><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Image with gradient and custom opacity</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

<!-- wp:cover {"url":"http://localhost:4759/wp-content/uploads/2022/02/tree2-7.jpeg","id":82,"dimRatio":70,"customOverlayColor":"#e5740b","isDark":false} -->
<div class="wp-block-cover is-light"><span aria-hidden="true" class="wp-block-cover__background has-background-dim-70 has-background-dim" style="background-color:#e5740b"></span><img class="wp-block-cover__image-background wp-image-82" alt="" src="http://localhost:4759/wp-content/uploads/2022/02/tree2-7.jpeg" data-object-fit="cover"/><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Image with custom color and custom opacity</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

<!-- wp:cover {"url":"http://localhost:4759/wp-content/uploads/2022/02/tree2-7.jpeg","id":82,"dimRatio":70,"customGradient":"linear-gradient(135deg,rgb(6,147,227) 0%,rgb(223,20,20) 22%,rgb(155,81,224) 93%)"} -->
<div class="wp-block-cover"><span aria-hidden="true" class="wp-block-cover__background has-background-dim-70 has-background-dim wp-block-cover__gradient-background has-background-gradient" style="background:linear-gradient(135deg,rgb(6,147,227) 0%,rgb(223,20,20) 22%,rgb(155,81,224) 93%)"></span><img class="wp-block-cover__image-background wp-image-82" alt="" src="http://localhost:4759/wp-content/uploads/2022/02/tree2-7.jpeg" data-object-fit="cover"/><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p class="has-text-align-center has-large-font-size">Image with custom gradient and opacity</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->

And all seemed to work as expected

Copy link
Member

@geriux geriux left a comment

Choose a reason for hiding this comment

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

This works well on mobile 🚀

@ramonjd ramonjd merged commit 4bfd7b3 into trunk Feb 9, 2022
@ramonjd ramonjd deleted the update/cover-block-background-classname branch February 9, 2022 00:24
@github-actions github-actions bot added this to the Gutenberg 12.6 milestone Feb 9, 2022
{
"clientId": "_clientId_0",
"name": "core/cover",
"isValid": false,
Copy link
Contributor

Choose a reason for hiding this comment

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

@ramonjd It was noticed over here that this block fixture results in an invalid block.

I'm not sure why that might be, it could be that something in the original html file was wrong (there was similar issue for a file block fixture - #38725) or that there's an issue with the deprecation.

Any ideas?

Copy link
Member Author

Choose a reason for hiding this comment

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

@talldan Thanks for the heads up. I've taken a look and it appears to be human error (mine).

The attribute "isDark":false should have a corresponding is-light classname on the container.

Getting a PR together to fix this now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Cover Affects the Cover Block - used to display content laid over a background image [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants