Skip to content

Commit a683c28

Browse files
WunderBartGlen Davies
andauthored
Cover Block: Fix regressions (#36406)
* Set default dim to 50% for media and 100% for solids Co-authored-by: Glen Davies <glen.davies@a8c.com>
1 parent 62ede3a commit a683c28

3 files changed

Lines changed: 38 additions & 9 deletions

File tree

packages/block-library/src/cover/style.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,22 @@
4343
* - Issue with background color specificity: https://github.com/WordPress/gutenberg/issues/26545
4444
* - Issue with alternative fix: https://github.com/WordPress/gutenberg/issues/26545
4545
*/
46+
47+
// the first selector is required for old Cover markup
48+
&.has-background-dim:not([class*="-background-color"]),
4649
.has-background-dim:not([class*="-background-color"]) {
4750
background-color: $black;
4851
}
4952

53+
// the first selector is required for old Cover markup
54+
&.has-background-dim::before,
5055
.has-background-dim::before {
5156
content: "";
5257
background-color: inherit;
5358
}
5459

60+
// the first selector is required for old Cover markup
61+
&.has-background-dim:not(.has-background-gradient)::before,
5562
.has-background-dim:not(.has-background-gradient)::before,
5663
.wp-block-cover__gradient-background {
5764
position: absolute;

packages/block-library/src/cover/transforms.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const transforms = {
1717
createBlock(
1818
'core/cover',
1919
{
20+
dimRatio: 50,
2021
url,
2122
alt,
2223
align,
@@ -43,6 +44,7 @@ const transforms = {
4344
createBlock(
4445
'core/cover',
4546
{
47+
dimRatio: 50,
4648
url: src,
4749
align,
4850
id,

packages/e2e-tests/specs/editor/blocks/cover.test.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ import {
1313
insertBlock,
1414
createNewPost,
1515
openDocumentSettingsSidebar,
16+
transformBlockTo,
1617
} from '@wordpress/e2e-test-utils';
1718

1819
async function upload( selector ) {
19-
await page.waitForSelector( selector );
20-
const inputElement = await page.$( selector );
20+
const inputElement = await page.waitForSelector(
21+
`${ selector } input[type="file"]`
22+
);
2123
const testImagePath = path.join(
2224
__dirname,
2325
'..',
@@ -30,9 +32,7 @@ async function upload( selector ) {
3032
const tmpFileName = path.join( os.tmpdir(), filename + '.png' );
3133
fs.copyFileSync( testImagePath, tmpFileName );
3234
await inputElement.uploadFile( tmpFileName );
33-
await page.waitForSelector(
34-
`.wp-block-cover img[src$="${ filename }.png"]`
35-
);
35+
await page.waitForSelector( `${ selector } img[src$="${ filename }.png"]` );
3636
return filename;
3737
}
3838

@@ -68,9 +68,7 @@ describe( 'Cover', () => {
6868
it( 'can set background image using image upload on block placeholder', async () => {
6969
await insertBlock( 'Cover' );
7070
// Create the block using uploaded image
71-
const sourceImageFilename = await upload(
72-
'.wp-block-cover input[type="file"]'
73-
);
71+
const sourceImageFilename = await upload( '.wp-block-cover' );
7472
// Get the block's background image URL
7573
const blockImage = await page.waitForSelector( '.wp-block-cover img' );
7674
const blockImageUrl = await blockImage.evaluate( ( el ) => el.src );
@@ -81,7 +79,7 @@ describe( 'Cover', () => {
8179
it( 'dims background image down by 50% by default', async () => {
8280
await insertBlock( 'Cover' );
8381
// Create the block using uploaded image
84-
await upload( '.wp-block-cover input[type="file"]' );
82+
await upload( '.wp-block-cover' );
8583
// Get the block's background dim color and its opacity
8684
const backgroundDim = await page.waitForSelector(
8785
'.wp-block-cover .has-background-dim'
@@ -194,4 +192,26 @@ describe( 'Cover', () => {
194192
)
195193
).toBeGreaterThan( 100 );
196194
} );
195+
196+
it( 'dims the background image down by 50% when transformed from the Image block', async () => {
197+
await insertBlock( 'Image' );
198+
// Upload image and transform to the Cover block
199+
await upload( '.wp-block-image' );
200+
await transformBlockTo( 'Cover' );
201+
202+
// Get the block's background dim color and its opacity
203+
const backgroundDim = await page.waitForSelector(
204+
'.wp-block-cover .has-background-dim'
205+
);
206+
const [
207+
backgroundDimColor,
208+
backgroundDimOpacity,
209+
] = await page.evaluate( ( el ) => {
210+
const computedStyle = window.getComputedStyle( el );
211+
return [ computedStyle.backgroundColor, computedStyle.opacity ];
212+
}, backgroundDim );
213+
214+
expect( backgroundDimColor ).toBe( 'rgb(0, 0, 0)' );
215+
expect( backgroundDimOpacity ).toBe( '0.5' );
216+
} );
197217
} );

0 commit comments

Comments
 (0)