Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the wp-has-aspect-ratio class from block embeds #4813

Merged
merged 3 commits into from
Jun 9, 2020

Conversation

pierlon
Copy link
Contributor

@pierlon pierlon commented Jun 5, 2020

Summary

As of Gutenberg 8.2, when the wp-has-aspect-ratio class is set on an embed block, it adds a large gap to the top of the embed. This breaks the visual parity of the AMP page when compared to its non-AMP counterpart. For example:

The wp-has-aspect-ratio class is not needed in the AMP context because the responsive layout of the embed will be handled natively. When the class is removed, visual parity is restored:

image

Fixes #4810

Related: #1683

Checklist

  • My pull request is addressing an open issue (please create one otherwise).
  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

@googlebot googlebot added the cla: yes Signed the Google CLA label Jun 5, 2020
@pierlon pierlon requested review from westonruter and schlessera June 5, 2020 07:49
@westonruter
Copy link
Member

westonruter commented Jun 7, 2020

I can see this change between 8.1 and 8.2:

image

It came from this PR: https://github.com/WordPress/gutenberg/pull/21599/files?diff=split&w=1

@westonruter
Copy link
Member

So what was formerly:

.wp-embed-responsive .wp-block-embed.wp-embed-aspect-16-9 .wp-block-embed__wrapper::before {
    padding-top: 56.25%;
}

Is now:

.wp-embed-responsive .wp-embed-aspect-16-9 .wp-block-embed__wrapper:before {
    padding-top: 56.25%;
}

@westonruter
Copy link
Member

Basically we want to prevent this new CSS rule from applying:

image

@westonruter
Copy link
Member

And this is the result when the wp-has-aspect-ratio class is removed.

$class
)

$classes = preg_replace_callback(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As opposed to using preg_replace_callback() would it make more sense to use array_filter()? So perhaps this would be marginally better:

$classes = array_filter(
	$classes,
	static function ( $class ) use ( &$responsive_width, &$responsive_height ) {
		if ( preg_match( '/^wp-embed-aspect-(?P<width>\d+)-(?P<height>\d+)$/', $class, $matches ) ) {
			$responsive_width  = $matches['width'];
			$responsive_height = $matches['height'];
			return false;
		}
		return 'wp-has-aspect-ratio' !== $class;
	}
);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For that matter, this could also be used instead of the array_diff() above as well. (Now updated the above.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in ae78190.

@westonruter westonruter added this to the v1.5.4 milestone Jun 7, 2020
Co-authored-by: Weston Ruter <westonruter@google.com>
@westonruter
Copy link
Member

I've confirmed that an embed looks properly in WP 5.4 both when Gutenberg 8.3 is active and when it is inactive.

@westonruter westonruter merged commit 3505c5e into develop Jun 9, 2020
@westonruter westonruter deleted the fix/4810-gap-above-embeds branch June 9, 2020 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Signed the Google CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Embed Blocks (YouTube, Vimeo): Extra space on top
3 participants