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(sbb-image): fix alt attribute and provide css var for aspect-ratio #2607

Merged
merged 6 commits into from
Apr 23, 2024

Conversation

mbleuer
Copy link
Contributor

@mbleuer mbleuer commented Apr 22, 2024

Preflight Checklist

Issue

There's no connected lyne-components issue.

Pull request checklist

  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Changes

Changes in this pull request:

  • Make sure that the alt attribute is always present on img elements, even if there is no alt text. Otherwise, supporting technologies may be tempted to interpret the image.
  • If the aspectRatio value is set to free, the component sets the CSS declaration to aspect-ratio: var(--image-aspect-ratio, auto); instead of aspect-ratio: auto;. This would allow consumers to enter the value for the CSS variable --image-aspect-ratio from outside the component. This would make it possible to set a different aspect ratio from viewport to viewport. People tried to achieve that behaviour with a workaround by defining two separate image components as can be seen here: https://www.sbbinsurance.li/ (inspect the markup of the hero image). This little fix would allow a lot of additional flexibility without having to break any existing functionality.

Browsers

I tested the build on the following browsers:

  • Firefox Desktop
  • Chrome Desktop
  • Edge Desktop
  • Safari Desktop
  • Chrome Mobile
  • Safari Mobile

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

Does this introduce a breaking change?

  • Yes
  • No

@github-actions github-actions bot added the pr: peer review required A peer review is required for this pull request label Apr 22, 2024
@mbleuer mbleuer closed this Apr 22, 2024
@github-actions github-actions bot added pr: peer review required A peer review is required for this pull request and removed pr: peer review required A peer review is required for this pull request labels Apr 22, 2024
@mbleuer mbleuer changed the title Fix/image improvements fix (sbb-image): alt attribute and aspect-ratio Apr 22, 2024
@mbleuer mbleuer reopened this Apr 22, 2024
@mbleuer mbleuer changed the title fix (sbb-image): alt attribute and aspect-ratio fix(sbb-image): alt attribute and aspect-ratio Apr 22, 2024
@github-actions github-actions bot requested a deployment to preview-main April 22, 2024 09:25 In progress
Copy link
Contributor

@jeripeierSBB jeripeierSBB left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution. I think, as mentioned, we should rename the variable with a breaking change.

src/components/image/image.ts Show resolved Hide resolved
@@ -275,6 +275,12 @@ export class SbbImageElement extends LitElement {
* Set an aspect ratio
* default is '16-9' (16/9)
* other values: 'free', '1-1', '1-2', '2-1', '2-3', '3-2', '3-4', '4-3', '4-5', '5-4', '9-16'
* If the aspectRatio value is set to 'free', the component sets the CSS declaration to
Copy link
Contributor

Choose a reason for hiding this comment

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

As we soon will release version 1.0, I think we should "sbb-"-prefix the very last not prefixed CSS var in the project :) this is causing a breaking change but it is ok for now. Furthermore, you could add a specific entry in the jsdoc section of the SbbImageElement class with "@cssprop":

@cssprop [--sbb-image-aspect-ratio=auto] - TBD...

With that it appears in readme.md and is therefore well documented and part of the public API.

see e.g. logo component for an example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the hint, I have indeed overlooked the documentation by @cssprop. It's added now.

I also renamed the variable. Since it is freshly introduced, it should not cause any breaking change? Or are you referring to --image-border-radius?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, I just realized it during re-review :D Probably I will create a follow-up PR for that. BTW, the image is, besides some minimal refactorings, still in the state you guys implemented it :)

@github-actions github-actions bot requested a deployment to preview-main April 22, 2024 12:05 In progress
@mbleuer
Copy link
Contributor Author

mbleuer commented Apr 22, 2024

Thanks for your contribution. I think, as mentioned, we should rename the variable with a breaking change.

Sure thing, thanks for the quick response! Please see the separate comment regarding the renaming/breaking change.

Copy link
Contributor

@jeripeierSBB jeripeierSBB left a comment

Choose a reason for hiding this comment

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

LGTM, thank you

@jeripeierSBB jeripeierSBB added the pr: lead review approved Pull request has been approved by a lead review label Apr 22, 2024
@jeripeierSBB jeripeierSBB changed the title fix(sbb-image): alt attribute and aspect-ratio fix(sbb-image): fix alt attribute and provide css var for aspect-ratio Apr 22, 2024
@jeripeierSBB jeripeierSBB merged commit 54d3192 into sbb-design-systems:main Apr 23, 2024
32 of 33 checks passed
@github-actions github-actions bot removed the pr: peer review required A peer review is required for this pull request label Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: lead review approved Pull request has been approved by a lead review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants