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

Fix aspect ratio in image container component on smaller screens #5179

Merged
merged 6 commits into from
Jun 26, 2024

Conversation

jmuzina
Copy link
Member

@jmuzina jmuzina commented Jun 20, 2024

Done

Fixes image container aspect ratio not being respected on smaller displays.

Fixes #5159

QA

  • Open demo
  • Verify that all images are the correct aspect ratio in all breakpoints.

Check if PR is ready for release

If this PR contains Vanilla SCSS code changes, it should contain the following changes to make sure it's ready for the release:

  • PR should have one of the following labels to automatically categorise it in release notes:
    • Feature 🎁, Breaking Change 💣, Bug 🐛, Documentation 📝, Maintenance 🔨.
  • Vanilla version in package.json should be updated relative to the most recent release, following semver convention:
    • if CSS class names are not changed it can be bugfix relesase (x.x.X)
    • if CSS class names are changed/added/removed it should be minor version (x.X.0)
    • see the wiki for more details
  • Any changes to component class names (new patterns, variants, removed or added features) should be listed on the what's new page.

Screenshots

image

Copy link
Contributor

@pastelcyborg pastelcyborg left a comment

Choose a reason for hiding this comment

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

Clever! It seems to me there are two big gotchas with this approach that we should consider:

  1. It won't work at all for full-bleed images; we'll either need an entirely new component or to use Modifiers to alter its approach significantly
  2. It relies on the images being presented fitting within a specific range of dimensions; particularly wide or tall images could be problematic

If we're comfortable with these compromises, I think it works.

scss/_patterns_image.scss Outdated Show resolved Hide resolved
@bartaz
Copy link
Member

bartaz commented Jun 20, 2024

Adapted from: https://nikitahl.com/css-aspect-ratio

@jmuzina
Copy link
Member Author

jmuzina commented Jun 24, 2024

Demos.haus did not automatically build last week due to some IS issues, but my push to resolve version # merge conflict just now seems to have triggered a demos.haus build successfully without posting the demo link to this PR.

Demo is at https://vanilla-framework-5179.demos.haus/

@lyubomir-popov
Copy link
Contributor

Borders on the structure example seem to have a bit too much contrast, unless this is intended:

looks like they are not using the correct colour. Shouild be the low-contrast one.

@jmuzina
Copy link
Member Author

jmuzina commented Jun 24, 2024

Borders on the structure example seem to have a bit too much contrast, unless this is intended:

looks like they are not using the correct colour. Shouild be the low-contrast one.

@lyubomir-popov
I accidentally posted that comment here, it should be at #5182

CC @pastelcyborg

@jmuzina jmuzina force-pushed the image-aspect-ratio-padding-hack branch from 53ed701 to 8023d09 Compare June 24, 2024 13:41
@jmuzina
Copy link
Member Author

jmuzina commented Jun 24, 2024

@pastelcyborg Can you please link your codepen here and talk a bit about pros/cons comparing these approaches?

@jmuzina
Copy link
Member Author

jmuzina commented Jun 24, 2024

@bartaz Can you please write a bit here about your alternative approach with applying the aspect ratio on parent & image and then using the image macro to specify metrics?

@lyubomir-popov
Copy link
Contributor

LGTM!

package.json Outdated Show resolved Hide resolved
@bartaz
Copy link
Member

bartaz commented Jun 25, 2024

@jmuzina @pastelcyborg I may have found a cleaner solution. First, switched to flex from grid, as we really don't need grid here (although it probably can be achieved with grid as well, but not by default). And second, and kind of the clue of the solution, is using the combination of max-height: 100% and object-fit: contain on the image itself. So that image doesn't make the container larger (container keeps it's aspect ratio), but the image doesn't get squashed, because of the contain.

Haven't found any issues with this approach yet.

@bartaz bartaz changed the title Fix aspect ratio utility on smaller screens Fix aspect ratio in image container component on smaller screens Jun 25, 2024
@bartaz bartaz marked this pull request as ready for review June 26, 2024 06:17
Copy link
Member Author

@jmuzina jmuzina left a comment

Choose a reason for hiding this comment

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

@bartaz GH won't let me approve this as it's originally my PR, but this looks good !

@jmuzina
Copy link
Member Author

jmuzina commented Jun 26, 2024

@jmuzina jmuzina added Review: Design +1 Review: Percy needed This PR needs a review of Percy for visual regressions and removed Review: Design needed labels Jun 26, 2024
@jmuzina
Copy link
Member Author

jmuzina commented Jun 26, 2024

Running a Percy check manually using Percy label as this was modified by Bartek before the Percy label bug (#5188 ) was fixed

Edit: Percy build created, and has expected changes :)

@jmuzina jmuzina added Review: Percy +1 and removed Review: Percy needed This PR needs a review of Percy for visual regressions labels Jun 26, 2024
Copy link
Member

@bartaz bartaz left a comment

Choose a reason for hiding this comment

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

on behalf of @jmuzina

@bartaz bartaz merged commit 333bbd6 into canonical:main Jun 26, 2024
12 checks passed
@jmuzina jmuzina deleted the image-aspect-ratio-padding-hack branch June 26, 2024 16:02
jmuzina added a commit to jmuzina/vanilla-framework that referenced this pull request Jun 26, 2024
…onical#5179)

* Fix aspect ratio utility on smaller screens

* Functionalize aspect ratio calculation & better document it

* Update _patterns_image.scss

update documentation to be more clear

* patch version bump for aspect ratio fix

* Switching to flexbox with image contained

* Revert "patch version bump for aspect ratio fix"

This reverts commit 8023d09.

---------

Co-authored-by: Bartek Szopka <bartek.szopka@canonical.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Image container aspect ratios do not apply on small screens
4 participants