diff --git a/lib/block-supports/background.php b/lib/block-supports/background.php
index 8e3c06159a120..1455d12fe883c 100644
--- a/lib/block-supports/background.php
+++ b/lib/block-supports/background.php
@@ -56,9 +56,10 @@ function gutenberg_render_background_support( $block_content, $block ) {
$background_styles['backgroundImage'] = isset( $block_attributes['style']['background']['backgroundImage'] ) ? $block_attributes['style']['background']['backgroundImage'] : array();
if ( ! empty( $background_styles['backgroundImage'] ) ) {
- $background_styles['backgroundSize'] = isset( $block_attributes['style']['background']['backgroundSize'] ) ? $block_attributes['style']['background']['backgroundSize'] : 'cover';
- $background_styles['backgroundPosition'] = isset( $block_attributes['style']['background']['backgroundPosition'] ) ? $block_attributes['style']['background']['backgroundPosition'] : null;
- $background_styles['backgroundRepeat'] = isset( $block_attributes['style']['background']['backgroundRepeat'] ) ? $block_attributes['style']['background']['backgroundRepeat'] : null;
+ $background_styles['backgroundSize'] = isset( $block_attributes['style']['background']['backgroundSize'] ) ? $block_attributes['style']['background']['backgroundSize'] : 'cover';
+ $background_styles['backgroundPosition'] = isset( $block_attributes['style']['background']['backgroundPosition'] ) ? $block_attributes['style']['background']['backgroundPosition'] : null;
+ $background_styles['backgroundRepeat'] = isset( $block_attributes['style']['background']['backgroundRepeat'] ) ? $block_attributes['style']['background']['backgroundRepeat'] : null;
+ $background_styles['backgroundAttachment'] = isset( $block_attributes['style']['background']['backgroundAttachment'] ) ? $block_attributes['style']['background']['backgroundAttachment'] : null;
// If the background size is set to `contain` and no position is set, set the position to `center`.
if ( 'contain' === $background_styles['backgroundSize'] && ! $background_styles['backgroundPosition'] ) {
diff --git a/lib/class-wp-theme-json-gutenberg.php b/lib/class-wp-theme-json-gutenberg.php
index a1e79a56a683b..11a506a416bb5 100644
--- a/lib/class-wp-theme-json-gutenberg.php
+++ b/lib/class-wp-theme-json-gutenberg.php
@@ -234,6 +234,7 @@ class WP_Theme_JSON_Gutenberg {
'background-position' => array( 'background', 'backgroundPosition' ),
'background-repeat' => array( 'background', 'backgroundRepeat' ),
'background-size' => array( 'background', 'backgroundSize' ),
+ 'background-attachment' => array( 'background', 'backgroundAttachment' ),
'border-radius' => array( 'border', 'radius' ),
'border-top-left-radius' => array( 'border', 'radius', 'topLeft' ),
'border-top-right-radius' => array( 'border', 'radius', 'topRight' ),
@@ -502,10 +503,11 @@ class WP_Theme_JSON_Gutenberg {
*/
const VALID_STYLES = array(
'background' => array(
- 'backgroundImage' => 'top',
- 'backgroundPosition' => 'top',
- 'backgroundRepeat' => 'top',
- 'backgroundSize' => 'top',
+ 'backgroundImage' => 'top',
+ 'backgroundAttachment' => 'top',
+ 'backgroundPosition' => 'top',
+ 'backgroundRepeat' => 'top',
+ 'backgroundSize' => 'top',
),
'border' => array(
'color' => null,
diff --git a/packages/block-editor/src/components/global-styles/background-panel.js b/packages/block-editor/src/components/global-styles/background-panel.js
index 7f3c3ed27e667..7d85f6cbaf282 100644
--- a/packages/block-editor/src/components/global-styles/background-panel.js
+++ b/packages/block-editor/src/components/global-styles/background-panel.js
@@ -195,6 +195,7 @@ function BackgroundImageToolsPanelItem( {
style,
inheritedValue,
themeFileURIs,
+ settings,
} ) {
const mediaUpload = useSelect(
( select ) => select( blockEditorStore ).getSettings().mediaUpload,
@@ -205,6 +206,13 @@ function BackgroundImageToolsPanelItem( {
...inheritedValue?.background?.backgroundImage,
};
+ const shouldShowBackgroundAttachmentControls =
+ settings?.background?.backgroundAttachment;
+
+ const attachmentValue = style?.background?.backgroundAttachment || {
+ ...inheritedValue?.background?.backgroundAttachment,
+ };
+
const replaceContainerRef = useRef();
const { createErrorNotice } = useDispatch( noticesStore );
@@ -289,6 +297,15 @@ function BackgroundImageToolsPanelItem( {
};
}, [] );
+ const toggleScrollWithPage = () =>
+ onChange(
+ setImmutably(
+ style,
+ [ 'background', 'backgroundAttachment' ],
+ attachmentValue === 'fixed' ? 'scroll' : 'fixed'
+ )
+ );
+
const hasValue = hasBackgroundImageValue( style );
const closeAndFocus = () => {
@@ -309,7 +326,9 @@ function BackgroundImageToolsPanelItem( {
const canRemove = ! hasValue && hasBackgroundImageValue( inheritedValue );
return (
-