-
Notifications
You must be signed in to change notification settings - Fork 1.1k
USWDS - Forms: Enhance form group error border in desktop widths #5999
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
Conversation
@cathybaptista Thank you for flagging! This stems from the .usa-form {
...
@include at-media("mobile-lg") {
max-width: units("mobile");
}
} This behavior is outside of the scope of this work and can be viewed without the error states enabled in any form that uses the Because of this, we shouldn't have to worry about it as being part of this work |
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.
@mahoneycm OK, given that this issue is out of scope, this works great to me. Approved!
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.
No issues found in Safari 17.6, Chromium 128, or Firefox 130.
Just a minor question and non-blocking issue. I can approve PR once resolved.
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 those answers, @mahoneycm.
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 your work on this @mahoneycm.
I have a few concerns about the design of the left bar here:
- The spacing between the form elements and the error bar is very tight. It doesn't feel consistent with the other spacing in our components.
- The bar exists in the negative margin, outside of the expected content region. This feels a bit risky to me. If users have a color shift at the edge of the content, or have split their layout at all, it might cause some unintended negative consequences.
To show what it might look like in the real world, I created a quick demo of the error states in a page layout in uswds-sandbox.
Possible solutions:
- I wonder if we can consider allowing the error state to shift the content, like it currently does at narrower window widths. In #5908, I actually found the content shift helpful because it drew my attention more to the error (Preview). We would have to investigate if there are any accessibility or usability concerns with a content shift like this, but my immediate instinct is that content shift might not necessarily be a bad thing.
- If we decide we must prevent any content shift and are comfortable living in the negative margins, maybe we can use
$theme-site-margins-width
to help inform the spacing. For example, if the site margins are at least >= 4 units, then move the bar -2 or -2.5 units. If the site margins are <4 units, move the bar to -1.5 units (or something). This might be fairly limited in thinking though — it might not address forms nested inside of components, etc. Alternatively, maybe we can create a setting that allows users to control the position of the error bar? - Consider using icon or other visual indicator instead of the vertical bar to visually indicate an error state (this is probably better as a follow-on task)
Curious what you all think.
cc: @mejiaj, @jaclinec, @thisisdano, @annepetersen
I think we should consider using a different visual indicator (i.e. icon) instead of the bar. To me, it stands out better than the vertical bar and doesn't have the content shift issue. It's also an expected and familiar convention used for errors in forms. I worry that the vertical bar is not noticeable, and see your point about the content shift possibly bringing needed attention to it. My initial instinct is that a content shift might not be a big deal usability- or accessibility-wise, but it's hard to know without testing or more research. There's a really good article on form error messages and it does mention layout shifts can be "noisy" but doesn't say it's a deal-breaker, FWIW. |
No issues from me, but I agree it looks tight. Increasing the spacing will cause it to break out even more or be even closer to the label. Changing the error style is a possible alternative, but higher LOE. We'd need to spike to find alternative error styles.
I mentioned in our meeting about layout shift, but according to this Smashing Magazine article, Core Web Vital's don't count shifts caused by user interaction.1. @amyleadem are you suggesting we leave the form elements as-is if we decide not proceed with removing the layout shift?
Allowing users to control the position of the error bar seems like a good idea. I'd avoid
This would require a spike for research and re-work that would increase the LOE. Not saying we shouldn't do it, but we should make these decisions much earlier to avoid scrapping work. My recommendation
Footnotes
|
I agree that choosing new error style (Option 3) would be a large LOE that would require more research, discussion, and prototyping than this issue/release would allow. In my opinion, the cleanest option is to just extend the current mobile styles (that have a content shift) to the desktop state (Option 1). But this might be informed too heavily by personal visual preference. @jaclinec, have we done any testing of error states in the "mobile" view? Curious if we have heard any complaints about the current content shift in error states there. |
We tested some error handling in the zebra batch testing, but it was error handling from the browser so it looked different: |
position: relative; | ||
|
||
@include at-media("desktop") { | ||
margin-left: units(-2.5); | ||
margin-left: -10px; |
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.
Matching the existing behaviors, this number is equal to the negation of border width + padding. Here I'm using a magic number but we could make the styles smarter by assigning variables and calculating the margin-left
.
$form-error-border-width: 2px;
$form-error-border-padding: rem-to-px(units(1)); // Alternatively, we could just set this to 8px
$form-error-negative-margin: -(
$form-error-border-width + $form-error-border-padding
);
...
.usa-form-group--error {
@include u-border-left($form-error-border-width, "error-dark");
padding-left: $form-error-border-padding;
position: relative;
@include at-media("desktop") {
margin-left: $form-error-negative-margin;
}
}
Update Sept 12I've updated the styles to reflect our discussion from dev sync (🔒). The PR description, testing instructions, and changelog have also been updated to match this new approach.
|
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.
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.
Confirming that this matches the styles we discussed. Noting that I personally find the styles to still be a bit tight, but it feels appropriate given the discussion we've had.
Possible follow-on tasks
- Elevate
$form-error-negative-margin
and$form-error-border-width
to theme settings so that users can customize error styles to fit their project needs. - Research alternative error state styles that replace the left border with an icon or other design
@thisisdano @heymatthenry @annepetersen This PR is approved from a technical standpoint, but we need your decision about if we should proceed with this change. We discussed in previous meetings that we might not want to release this until we have some data or feedback to back up the need for it. Curious what you think! |
Correct me if I’m wrong, but I thought the decision we made in the last meeting when we discussed this was not to release it for now |
Closing in favor of #6204 |
Summary
Improved form group error syles. Form group error border width and relevant spacing have been reduced.
As discussed in dev sync (🔒) and this internal slack thread (🔒)
Breaking change
This is not a breaking change.
Related issue
Closes #5998
Related pull requests
Changelog →
Preview link
Form group error preview →
Sandbox demo page →
Problem statement
In desktop widths, the form group error border uses negative margin and is pushed out of the parent container.
Solution
After discussion, we opted to keep the original breakpoint to reduce content shift in desktop views, and reduce the size of the border, the padding between the border and the content, as well as the negative margin that pushes it left.
Major changes
Note: Desktop content does not shift when form group error style are added, mobile content does. This matches the current behavior of develop.
Testing and review
Screenshots
Screenshots showing the placement of content and border relative to div and margin
2rem
of margin fromgrid-layout
)