Make WordPress Core


Ignore:
Timestamp:
07/31/2024 02:39:46 AM (16 months ago)
Author:
ramonopoly
Message:

Background: add background attachment support to theme.json styles

Introduces the ability to specify a value for background.backgroundAttachment in theme.json styles.

The theme.json value determines the CSS value for the background-attachment property.

This feature was introduced into the Gutenberg plugin in version 18.9.

Props andrewserong, mukesh27, noisysocks, ramonopoly.

Fixes #61720

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/theme/wpThemeJson.php

    r58797 r58834  
    49984998     * @ticket 61123
    49994999     * @ticket 61165
     5000     * @ticket 61720
    50005001     */
    50015002    public function test_get_top_level_background_image_styles() {
     
    50055006                'styles'  => array(
    50065007                    'background' => array(
    5007                         'backgroundImage'    => array(
     5008                        'backgroundImage'      => array(
    50085009                            'url' => 'http://example.org/image.png',
    50095010                        ),
    5010                         'backgroundSize'     => 'contain',
    5011                         'backgroundRepeat'   => 'no-repeat',
    5012                         'backgroundPosition' => 'center center',
     5011                        'backgroundSize'       => 'contain',
     5012                        'backgroundRepeat'     => 'no-repeat',
     5013                        'backgroundPosition'   => 'center center',
     5014                        'backgroundAttachment' => 'fixed',
    50135015                    ),
    50145016                ),
     
    50215023        );
    50225024
    5023         $expected_styles = "html{min-height: calc(100% - var(--wp-admin--admin-bar--height, 0px));}:root :where(body){background-image: url('http://example.org/image.png');background-position: center center;background-repeat: no-repeat;background-size: contain;}";
     5025        $expected_styles = "html{min-height: calc(100% - var(--wp-admin--admin-bar--height, 0px));}:root :where(body){background-image: url('http://example.org/image.png');background-position: center center;background-repeat: no-repeat;background-size: contain;background-attachment: fixed;}";
    50245026        $this->assertSame( $expected_styles, $theme_json->get_styles_for_block( $body_node ), 'Styles returned from "::get_stylesheet()" with top-level background styles type do not match expectations' );
    50255027
     
    50295031                'styles'  => array(
    50305032                    'background' => array(
    5031                         'backgroundImage'    => "url('http://example.org/image.png')",
    5032                         'backgroundSize'     => 'contain',
    5033                         'backgroundRepeat'   => 'no-repeat',
    5034                         'backgroundPosition' => 'center center',
    5035                     ),
    5036                 ),
    5037             )
    5038         );
    5039 
    5040         $expected_styles = "html{min-height: calc(100% - var(--wp-admin--admin-bar--height, 0px));}:root :where(body){background-image: url('http://example.org/image.png');background-position: center center;background-repeat: no-repeat;background-size: contain;}";
     5033                        'backgroundImage'      => "url('http://example.org/image.png')",
     5034                        'backgroundSize'       => 'contain',
     5035                        'backgroundRepeat'     => 'no-repeat',
     5036                        'backgroundPosition'   => 'center center',
     5037                        'backgroundAttachment' => 'fixed',
     5038                    ),
     5039                ),
     5040            )
     5041        );
     5042
    50415043        $this->assertSame( $expected_styles, $theme_json->get_styles_for_block( $body_node ), 'Styles returned from "::get_stylesheet()" with top-level background image as string type do not match expectations' );
    50425044    }
     
    50445046    /**
    50455047     * @ticket 61588
     5048     * @ticket 61720
    50465049     */
    50475050    public function test_get_block_background_image_styles() {
     
    50535056                        'core/group' => array(
    50545057                            'background' => array(
    5055                                 'backgroundImage'    => "url('http://example.org/group.png')",
    5056                                 'backgroundSize'     => 'cover',
    5057                                 'backgroundRepeat'   => 'no-repeat',
    5058                                 'backgroundPosition' => 'center center',
     5058                                'backgroundImage'      => "url('http://example.org/group.png')",
     5059                                'backgroundSize'       => 'cover',
     5060                                'backgroundRepeat'     => 'no-repeat',
     5061                                'backgroundPosition'   => 'center center',
     5062                                'backgroundAttachment' => 'fixed',
    50595063                            ),
    50605064                        ),
     
    50955099        );
    50965100
    5097         $group_styles = ":root :where(.wp-block-group){background-image: url('http://example.org/group.png');background-position: center center;background-repeat: no-repeat;background-size: cover;}";
     5101        $group_styles = ":root :where(.wp-block-group){background-image: url('http://example.org/group.png');background-position: center center;background-repeat: no-repeat;background-size: cover;background-attachment: fixed;}";
    50985102        $this->assertSame( $group_styles, $theme_json->get_styles_for_block( $group_node ), 'Styles returned from "::get_styles_for_block()" with block-level background styles as string type do not match expectations' );
    50995103    }
Note: See TracChangeset for help on using the changeset viewer.