-
Notifications
You must be signed in to change notification settings - Fork 1k
Button/Icon: Improve default appearance of button with icon #4493
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
| margin-left: -0.5rem; | ||
| margin-right: 0.5rem; |
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.
I'm open to feedback about the specific offsets here, since it's all a bit subjective.
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.
I'm open to feedback about the specific offsets here, since it's all a bit subjective.
I adjusted this further in 5abd934 after some discussion with our in-team UX folks, based on differences in appearance across icons. Previously, the idea was to try to create a "centered" effect between the left edge of the button and the start of the text. With 5abd934, the idea is more to have the icon adjacent to the text, with a bit of margin. This is offset (negated) a bit based on some built-in padding to most icons, which appears to be at least 2px inside the default 24px viewport. The idea with the calculation in 5abd934 is to adjust this relative to the font size of the button, so that the spacing can increase a bit with larger buttons (e.g. the "Big" variant).
develop |
dd973bd (original proposal) |
5abd934 (revised proposal) |
|---|---|---|
| margin-top: -0.5 * ($icon-inline-size-magic-number - lh($theme-button-font-family, 1)); | ||
| margin-bottom: -0.5 * ($icon-inline-size-magic-number - lh($theme-button-font-family, 1)); |
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.
These margins exist to offset the height increase which would otherwise occur due to the icon. With default settings, a button defines a line-height of 0.9, but this doesn't apply to the SVG, so the idea is to correct it by subtracting the difference (0.1em) equally from the top and bottom of the icon (margin-top: -0.05em; margin-bottom: -0.05em;).
|
One noteworthy consideration we're encountering as we're preemptively implementing these styles in our project: The However, if a button is stretched using a width utility (e.g. The
|
|
Sorry for the late response. I think this is a needed improvement, but needs discussion on how to best handle the use cases. For example, any specific styles tied to icon being inside buttons might need it's own modifier class. In the meantime I've tagged it for Needs discussion and will add @amyleadem and @thisisdano as reviewers. |
|
Thank you for the contribution and I apologize it took so long to address. I've created a new PR to add basic alignment to icons in buttons without relying on Closing in favor of #5398. |
Description
This pull request seeks to improve the default appearance of using an Icon within a Button.
Using an icon to accompany a button's text is a common pattern, one which is even recommended in the Icon usability guidance:
Additional information
Slack discussion context: https://gsa-tts.slack.com/archives/C3F14AHSQ/p1643382119000500
Screenshots
The goal with this implementation was to avoid requiring any additional markup to support using an icon in a button. Ideally, a developer should be able to insert the icon and it "just works".
A couple open questions worth considering:
_icon.scssthe best file for these styles to reside? Or would a button stylesheet make more sense? Or is this something completely different?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.