Skip to content

Commit

Permalink
Cover block: Change dimRatio to 50 if media added and dimRatio is set…
Browse files Browse the repository at this point in the history
… to 100 (#35789)

* Change opacity to 50 if media added and opacity is set to 100 to prevent background color obscuring image

* Fixes cover opacity bug on mobile (#35792)

Co-authored-by: Glen Davies <glen.davies@a8c.com>
Co-authored-by: Antonis Lilis <antonis.lilis@automattic.com>
  • Loading branch information
3 people committed Oct 20, 2021
1 parent 3df8596 commit 7b7b0d0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/block-library/src/cover/edit.js
Expand Up @@ -333,7 +333,7 @@ function CoverEdit( {
gradientValue,
setGradient,
} = __experimentalUseGradient();
const onSelectMedia = attributesFromMedia( setAttributes );
const onSelectMedia = attributesFromMedia( setAttributes, dimRatio );
const isUploadingMedia = isTemporaryMedia( id, url );

const [ prevMinHeightValue, setPrevMinHeightValue ] = useState( minHeight );
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/cover/edit.native.js
Expand Up @@ -190,7 +190,7 @@ const Cover = ( {

const onSelectMedia = ( media ) => {
setDidUploadFail( false );
const onSelect = attributesFromMedia( setAttributes );
const onSelect = attributesFromMedia( setAttributes, dimRatio );
onSelect( media );
};

Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/cover/shared.js
Expand Up @@ -32,7 +32,7 @@ export function dimRatioToClass( ratio ) {
: 'has-background-dim-' + 10 * Math.round( ratio / 10 );
}

export function attributesFromMedia( setAttributes ) {
export function attributesFromMedia( setAttributes, dimRatio ) {
return ( media ) => {
if ( ! media || ! media.url ) {
setAttributes( { url: undefined, id: undefined } );
Expand Down Expand Up @@ -65,6 +65,7 @@ export function attributesFromMedia( setAttributes ) {
}

setAttributes( {
dimRatio: dimRatio === 100 ? 50 : dimRatio,
url: media.url,
id: media.id,
alt: media?.alt,
Expand Down

0 comments on commit 7b7b0d0

Please sign in to comment.