-
Notifications
You must be signed in to change notification settings - Fork 934
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
USWDS - Utilities: use CSS aspect-ratio #4811
Conversation
|
@mejiaj I haven't updated the documentation yet (waiting for code to finalize), but I was hoping you could look over the code and let me know if you have any questions or concerns. It ended up being a little more layered than expected, so let me know if it would be helpful to chat through it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I like the approach of using modern CSS techniques. Do you imagine this would be a breaking change for users?
I imagined the approach would be a mix of old code and new (using @supports for the newer CSS feature).
|
@mejiaj I also have consolidated the aspect-ratio code inside the This has meant removing styles from the Additionally, I have done my best to answer the questions in your comments. If you have any questions or comments, please let me know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed answers! I like how you used @supports to enhance aspect ratios where applicable.
Added a few comments for deprecating features. Also added a question for hero structure with add-aspect.
This has meant removing styles from the $add-aspect utility builder. I was wondering - is there any reason to keep this code in this updated/near-empty state? As a test, I have commented this code out and it has no impact on the CSS.
I think it's only needed for generating the utility classes. It makes sense to keep it for now.
|
@mejiaj I have made the following updates:
Thanks for the helpful comments! Please let me know if you see anything else. |
|
@mejiaj Afterthought: Is it safe to deprecate the entire |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is approved, nice work!
Since this is a big change to how aspect works, could you try to write up the draft release note for it? Anywhere in the PR description is fine, ty!
Thanks @mejiaj. Wrote up a first pass at a draft release note. Please feel free to edit if you see the need. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
Draft Release Notes
Integrated the CSS
aspect-ratioproperty into ouradd-aspectutility and mixins. This change aligns us more closely with expected CSS behavior, while also extending the capabilities ofadd-aspect. Users can now applyadd-aspectdirectly to media and media wrappers — without the need to use.usa-embed-container. This update is backwards compatible and was written to preserve previous behavior for browsers that do not support the CSSaspect-ratioproperty.Description
Closes: #4244
Preview link: Add aspect test scenarios
Problem
Our
add-aspectutility does not behave in the same way that the native CSSaspect-ratiobehaves. CSSaspect-ratiouses more straightforward CSS and also has increased capabilities. Because this CSS property is becoming increasingly accepted (Can I Use info), this discrepancy will likely cause increasing confusion to users.Solution
Using the CSS
aspect-ratioproperty in ouradd-aspectutility will create a more predictable experience for the user, as well as add some capability that our current setup does not allow.Added capabilities:
<img>wrapper elements and also directly to<img>elements.usa-embed-containerin addition toadd-aspect-xxxBefore/After comparison
For reference, you can see the preliminary side-by-side demonstration of the additional use cases in this demo of the old vs new functionality (built in a separate PR).
Additionally, for comparison here is a screenshot of the same test page markup from this PR with our current add-aspect build in
develop(as seen on Chrome):aspect-ratioacross browsers. However, the inconsistencies/failures are on use cases that our add-aspect ratio does not currently cover, so users will not be losing any capability.- Tested in: Safari, Firefox, Chrome, iOS 15 safari, Android 11 chrome,
Found browser differences:
Android struggles to preserve ratio when height attribute is added:
Tasks
embed-containerandadd-aspect-ratioWrite/improve documentation on how to use.add-aspect-AxB(Will create once we solidify code)Testing
To test utility classes:
To test mixins:
Uncomment these lines in add-aspect.scss:
Then, either:
test-add-aspectandtest-add-aspect-imageelements on the add-aspect test pageNotice that the element changes from 16x9 to 1x1 at the desktop breakpoint.
Additional information
Before you hit Submit, make sure you’ve done whichever of these applies to you:
npm testand make sure the tests for the files you have changed have passed.