Skip to content

Bug: wrong class name has-background-dim-0 with opacity 0.5 #27495

Closed

Description

@vHeemstra

Description
When you set the transparency on a cover block to 1 through 4 in the editor, this will be rounded to 0 but is not ignored by the ! ratio check. So it ends up with a class name of has-background-dim-0 which has no styling, but defaults to opacity 0.5 because of the .wp-block-cover__gradient-background class default opacity. This happens in the editor WYSIWYG as well as on the front-end.

Possible solution 1

export function dimRatioToClass( ratio ) {
return ratio === 0 || ratio === 50 || ! ratio
? null
: 'has-background-dim-' + 10 * Math.round( ratio / 10 );
}

Let line #59 also check on the rounded opacity value by adding || 0 === Math.round( ratio / 10 ) or similar.

Possible solution 2

@for $i from 1 through 10 {
&.has-background-dim.has-background-dim-#{ $i * 10 } {
&:not(.has-background-gradient)::before,
.wp-block-cover__gradient-background {
opacity: $i * 0.1;
}
}
}

Have the SCSS file include a has-background-dim-0 class definition with opacity: 0 by starting the @for on 0.

NB:
I'm not sure if this the only place where this bug occurs. (Not that familiar with the code base ;) )

Activity

  1. added
    [Block] Cover
    [Type] Bug
    Good First Issue
    on Dec 4, 2020
  2. added
    [Status] In Progress
    on Dec 8, 2020
  3. ramonjd commented on Feb 15, 2022

    @ramonjd
    Member

    I can't reproduce this. I think it might have been addressed by #35065 or an earlier PR.

    Feel free to reopen if the problem persists. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good First Issue[Block] Cover[Status] In Progress[Type] Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions