Skip to content

Conversation

Adi-ty
Copy link
Contributor

@Adi-ty Adi-ty commented Jul 14, 2025

What?

Preserves the hasParallax attribute when switching a Cover block from video to image.
Closes #70701

Why?

Fixed background option disappears when switching from video to image in cover block

How?

  • When switching media, if the previous background was a video and had hasParallax set, this attribute is preserved when switching to an image.

Testing Instructions

  1. Add a Cover block.
  2. Select an image and confirm "Fixed background" is available.
  3. Replace with a video.
  4. Replace again with an image.
  5. Confirm "Fixed background" remains available.

Screenshots or screencast

Screen.Recording.2025-07-14.at.10.45.56.AM.mov

… block

fix: preserve hasParallax when switching from video to image in Cover block
Fixes WordPress#70701
@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended [Block] Cover Affects the Cover Block - used to display content laid over a background image labels Jul 14, 2025
@Adi-ty Adi-ty marked this pull request as ready for review July 14, 2025 08:29
Copy link

github-actions bot commented Jul 14, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Adi-ty <iamadisingh@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: ldanielgiuliani <ldanielgiuliani@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@Mamaduka
Copy link
Member

An alternative solution will be to cast the hasParallax value used with controls to a boolean. It's expected to be a boolean, but after replacement, it becomes undefined because the default value isn't picked up again.

I think this became an issue after ToolsPanelItem refactoring, the component expects this hasValue to return a boolean.

Example Diff

diff --git packages/block-library/src/cover/edit/inspector-controls.js packages/block-library/src/cover/edit/inspector-controls.js
index 0793f81085e..86bb2810feb 100644
--- packages/block-library/src/cover/edit/inspector-controls.js
+++ packages/block-library/src/cover/edit/inspector-controls.js
@@ -208,7 +208,7 @@ export default function CoverInspectorControls( {
 								<ToolsPanelItem
 									label={ __( 'Fixed background' ) }
 									isShownByDefault
-									hasValue={ () => hasParallax }
+									hasValue={ () => !! hasParallax }
 									onDeselect={ () =>
 										setAttributes( {
 											hasParallax: false,
@@ -219,7 +219,7 @@ export default function CoverInspectorControls( {
 									<ToggleControl
 										__nextHasNoMarginBottom
 										label={ __( 'Fixed background' ) }
-										checked={ hasParallax }
+										checked={ !! hasParallax }
 										onChange={ toggleParallax }
 									/>
 								</ToolsPanelItem>

@Adi-ty
Copy link
Contributor Author

Adi-ty commented Jul 14, 2025

@Mamaduka Thank you for the suggestion!
I've updated the code to cast hasParallax to a boolean in both the hasValue and checked props as recommended. Let me know if anything else is needed!

Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

Thanks for contributing, @Adi-ty!

@Mamaduka Mamaduka merged commit e28685d into WordPress:trunk Jul 14, 2025
42 of 60 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.3 milestone Jul 14, 2025
cbravobernal pushed a commit that referenced this pull request Jul 15, 2025
… block (#70703)

Co-authored-by: Adi-ty <iamadisingh@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: ldanielgiuliani <ldanielgiuliani@git.wordpress.org>
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] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fixed background option disappears when switching from video to image in cover block
2 participants