Skip to content

Conversation

amyleadem
Copy link
Contributor

@amyleadem amyleadem commented Nov 24, 2023

Summary

Fixed a bug that caused $theme-site-margins-width to adjust alignment inside the alert and site alert components.

Important

At desktop widths, the site alert and alert components will no longer share left and right alignment. If users want alerts to align with site alert, they should use site alert markup.

Breaking change

⚠️ This is potentially a breaking change.

Alignment on the alert and site alert components will likely shift from this change. Confirm that your implementation aligns as expected.

Related issue

Closes #5583

Related pull requests

Changelog PR

Preview link

Problem statement

When $theme-site-margins-width receives custom values, it can cause the the content inside the alert component to overlap or become misaligned with the banner and other components. For example, setting $theme-site-margins-width: 1px results in the following:

image

Setting the value to $theme-site-margins-width: 15` results in the following:

image

And $theme-site-margins-width: 6`:

image

Solution

This PR rebuilds the alignment in the alert and site alert components so that they consume settings values as expected.

Screenshots

Mobile

image

Desktop

image

Testing and review

Generally

  1. Confirm code meets USWDS standards
  2. Confirm that it is reasonable to ask users to use site-alert markup when they want the content to align with site margins.

Default state

  1. Open up the Storybook previews (Test - Alert comparison test story | Test - Alerts in template story) of this component:
    • At mobile, confirm that all alert and site alert variants have the same left and right alignment
    • At desktop, confirm that site alert content shares left and right alignment with banner and footer
    • At desktop, confirm that all alert variants share the same left alignment

With settings adjustments

Important

All alert component settings apply to site alert except $theme-alert-padding-x. This is because the horizontal alignment of the site alert is fundamentally different from the alert component. We will update the documentation to clarify this in the changelog PR. The conversation about this decision is outlined in this comment thread

  1. Run a local build of uswds from this branch
  2. Open the "Alert components comparison" story (http://localhost:6006/?path=/story/components-alert--alert-components-comparison)
  3. Set $theme-site-margins-width to 15 and 0. For each instance, confirm in the test stories that:
    1. At mobile, all alerts and site alerts share the same left and right alignment
    2. At desktop, all site alerts share the same left and right alignment as the banner
    3. At desktop, all alerts share the same left and right alignment as each other
    4. The gap between the icon and the alert text does not change from default
  4. Set $theme-alert-bar-width to 15 and 0. For each instance, confirm in the test stories that:
    1. The left colored bar adjusts to match the declared width
    2. Text content does not overlap with the colored bar
  5. Set $theme-alert-padding-x to 15 and 2. For each instance, confirm in the test stories that:
    1. At desktop and mobile, the left and right alignment on the alerts adjusts to match the new setting value
    2. At desktop, all site alerts maintain the same left and right alignment as the banner
    3. At mobile, all site alerts share the same left and right alignment of 2.5 units
  6. Set $theme-alert-icon-size to 6 and 2. For each instance, confirm in the test stories that:
    1. The standard icon size adjusts to match the declared value (this should not affect the slim icon implementations)
    2. At all window widths, the text for alert and site alert components adjusts left alignment to match the new icon size. The gap between the icon and the text should not change, and the elements should not overlap.
  7. Set $theme-alert-padding-y to 6 and 0. For each instance, confirm in the test stories that:
    1. The vertical padding adjusts to match the declared value (this does not apply to the slim variant)
    2. All other elements align as expected

Compare to 3.1.0

Additionally, you can compare this PR with the alerts in the release-3.1.0 branch to see the components before the alignment adjustments in 3.2.0.

The main differences that I found between the 3.1.0 and this PR are:

  • Adjusting $theme-alert-padding-x adjusted the gap between the icon and text in 3.1.0. It no longer does that in this PR, which I think is an improvement. (The gap is now consistent regardless of x padding size)
    image
  • The site alert in 3.1.0 does NOT have a bar on left side of the component. It does in develop and in this PR.

Copy link
Contributor Author

@amyleadem amyleadem left a comment

Choose a reason for hiding this comment

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

@mejiaj I believe I have addressed all your comments and made the updates requested in our discussion today. I did the following:

  1. Reverted the change that created additional variants for site alert. Site alert and alert will continue to have the same variants that they did in 3.8.2 and before.
  2. Updated the alignment methods so that it uses padding rather than left and margin. This should improve clarity in the setting names and will make styling the components a little more intuitive.
  3. Made no change regarding the role of $theme-alert-padding-x in site alert. After our group discussion, we agreed that all other alert settings will affect site alert but not this one. This is because of the core horizontal alignment differences across components. As a next step, I will enhance the related documentation to make this clear.
  4. Created a shared JSON file (test-usa-alert-content.JSON) for alert test content and removed the content from the test twig files.
  5. Confirmed that the template markup is different enough to keep them separate (but let me know if you disagree)

I think that is it. Let me know if you have any questions or want to walk through this in real time together.

@amyleadem amyleadem requested a review from mejiaj September 23, 2024 22:06
- This prevents an error with build:html
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note

I originally placed this file in the /test-patterns directory, but it caused an error when running npm run build:html. I moved it to a couple of different spots, but the only place it didn't cause an error is in this /content directory. If you see a better place for it, please let me know!

Copy link
Contributor

@mejiaj mejiaj left a comment

Choose a reason for hiding this comment

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

@amyleadem I was able to see the new defaults and modify settings in your sandbox branch [al-test-5636-alert-align] without any issues. Thanks for creating that!

Settings I tested:

// _uswds-theme.scss

// Tested with varying combinations.
@use "uswds-core" with (
  $theme-site-margins-width: 4,
  $theme-alert-bar-width: 2,
  $theme-alert-icon-size: 2,
  $theme-alert-padding-x: 4,
  $theme-alert-padding-y: 4,
);

Added a few comments to improve readability and code re-use templates.

@amyleadem amyleadem requested a review from mejiaj September 27, 2024 22:39
Copy link
Contributor

@mejiaj mejiaj left a comment

Choose a reason for hiding this comment

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

@amyleadem one suggestion for polish, but otherwise LGTM.

@amyleadem amyleadem requested a review from mejiaj September 30, 2024 23:55
Copy link
Contributor

@CTGM-Bixal CTGM-Bixal left a comment

Choose a reason for hiding this comment

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

Default Settings

  • At mobile, confirm that all alert and site alert variants have the same left and right alignment
  • At desktop, confirm that site alert content shares left and right alignment with banner and footer
  • At desktop, confirm that all alert variants share the same left alignment

Settings Adjustments

Set $theme-site-margins-width to 15 and 0

  • At mobile, all alerts and site alerts share the same left and right alignment

Maybe I'm misunderstanding what I should be seeing from this test, but I see the site-alert alignment different from the alert alignment in mobile view? This screenshot is with theme-site-margins-width set to 0.
Screenshot 2024-10-01 at 3 09 13 PM

  • At desktop, all site alerts share the same left and right alignment as the banner
  • At desktop, all alerts share the same left and right alignment as each other
  • The gap between the icon and the alert text does not change from default

Everything else looks good here!

Set $theme-alert-bar-width to 15 and 0

  • The left colored bar adjusts to match the declared width
  • Text content does not overlap with the colored bar

Everything looks good here!

Set $theme-alert-padding-x to 15 and 2. For each instance, confirm in the test stories that

  • At desktop and mobile, the left and right alignment on the alerts adjusts to match the new setting value
  • At desktop, all site alerts maintain the same left and right alignment as the banner
  • At mobile, all site alerts share the same left and right alignment of 2.5 units

Everything looks good here!

Set $theme-alert-icon-size to 6 and 2

  • The standard icon size adjusts to match the declared value (this should not affect the slim icon implementations)
  • At all window widths, the text for alert and site alert components adjusts left alignment to match the new icon size. The gap between the icon and the text should not change, and the elements should not overlap.

Everything looks good here!

Set $theme-alert-padding-y to 6 and 0

  • The vertical padding adjusts to match the declared value (this does not apply to the slim variant)
  • All other elements align as expected

Everything looks good here!

Other

  • Adjusting $theme-alert-padding-x adjusted the gap between the icon and text in 3.1.0. It no longer does that in this PR

Confirmed that the gap between icon and text in this PR does not change based on $theme-alert-padding-x setting

Confirmed that the bar on the left side of the component appears in this PR

@amyleadem
Copy link
Contributor Author

@RachelCorsino
I consider the screenshot you shared to be expected behavior in uswds-sandbox because the alert and other main content lives inside a grid-container that has some extra x-padding, whereas the site alert does not. So the difference in alignment isn't coming from the component itself.

If you look at the Test alert site alert comparison story, you should see that the two components align in mobile. Please let me know if you have any questions!

@CTGM-Bixal
Copy link
Contributor

@amyleadem - I see it working as expected in the Test alert site alert comparison story.

Everything looks good from my tests - Approved!

@amyleadem amyleadem requested review from heymatthenry and thisisdano and removed request for mahoneycm October 1, 2024 20:45
Copy link
Contributor

@thisisdano thisisdano left a comment

Choose a reason for hiding this comment

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

A lot of work here! It will be nice to move this gnarly little issue off your plate!

@thisisdano thisisdano merged commit 3f06476 into develop Oct 3, 2024
5 checks passed
@thisisdano thisisdano deleted the al-alert-icon-alignment branch October 3, 2024 03:36
@thisisdano thisisdano mentioned this pull request Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

USWDS - Alert/Site alert: Fix content alignment issues
6 participants