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

Add aspect ratio selector to Cover Block #54032

Closed
henriqueiamarino opened this issue Aug 29, 2023 · 3 comments · Fixed by #56897
Closed

Add aspect ratio selector to Cover Block #54032

henriqueiamarino opened this issue Aug 29, 2023 · 3 comments · Fixed by #56897
Labels
[Block] Cover Affects the Cover Block - used to display content laid over a background image [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Type] Task Issues or PRs that have been broken down into an individual action to take

Comments

@henriqueiamarino
Copy link

What problem does this address?

A similar issue was closed in 2020, #23092. Today, we can only edit the Minimum height of cover, but due to the current stage of Gutenberg, we can fix it consistently.

Cover block styles today
pr_cover-block

What is your proposed solution?

Add the aspect ratio selector just as we have on image blocks.

Image block styles today
pr_image-block

@jordesign jordesign added [Type] Enhancement A suggestion for improvement. [Block] Cover Affects the Cover Block - used to display content laid over a background image labels Aug 29, 2023
@mtias mtias added [Type] Task Issues or PRs that have been broken down into an individual action to take [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi and removed [Type] Enhancement A suggestion for improvement. labels Nov 30, 2023
@andrewserong
Copy link
Contributor

andrewserong commented Dec 6, 2023

@jasmussen did you have an idea in mind for how this should ideally work? From a little digging, aspect-ratio seems to both have pretty good browser support, and from hacking around in Codepen, content that extends beyond the height of the container will naturally extend the container, so it seems like it might behave similarly to minimum height in that respect (which IMO is a good way for it to behave). Basically it sounds like it'd work like "try to contain to an aspect ratio if the content will allow it, otherwise expand the container".

If exploring controls for this, I think we should probably look at it as part of block supports, so that we could (potentially) enable it for both Cover and Group blocks at the same time, instead of tying it specifically to the Cover block. It also seems a little related to background image support, so I've linked to this issue from #54336.

I'm currently looking into a few other tasks at the moment, but if no-one beats me to it, I'm happy to have a hack around with this idea and see what seems feasible. I imagine this issue could be one that's a fair bit more complex than it appears at first glance, but it sounds worthwhile to try to get a prototype working so we can see how challenging it might be to get working 🙂

@jasmussen
Copy link
Contributor

Thanks so much for looking. Yes I was indeed hoping to use aspect-ratio, just like the Image block does:

CSS applied to image block on the frontend

In fact, I was hoping we could transplant more or less the exact behavior from how the aspect selector works on the Image block. Here's a GIF of the image block in the editor:

image block

Shown in that GIF:

  • Selecting the image block and highlighting the aspect ratio dropdown, as well as width and height, in the inspector.
  • Selecting Square (1:1) and then Wide (16:9) aspect ratios and seeing the image adjust as a result
  • Adding an explicit height to the "height" control, and showing what that has of an effect.

Notably the last part — when you add a height, it combines with the aspect ratio, so 16:9 plus "Wide" makes for a small landscape picture. This is mainly relevant to the Cover block in that it only has a max-height control. Now if we just add the aspect ratio control and ignore the width and height controls (though if it's easier to add those to at the same time that's fine), then presumably the end result would be the same. If you apply an aspect ratio, then that property will control the height based on the width, until the max-height is reached.

I'd agree a block supports would be great, this is indeed useful to Group as well.

@andrewserong
Copy link
Contributor

I have a WIP PR exploration into this feature over in #56897. There are a few potential limitations and peculiarities with how aspect ratio works, but it's ready for playing with if folks would like to take a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Cover Affects the Cover Block - used to display content laid over a background image [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants