-
Notifications
You must be signed in to change notification settings - Fork 201
fix(button): support for wrapping text #2248
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
3383b26
to
e28f7b7
Compare
🚀 Deployed on https://pr-2248--spectrum-css.netlify.app |
e28f7b7
to
eebd23f
Compare
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.
One comment about the static color variant background colors.
I looked at it on Safari, Firefox, and WHCM and didn't see any other issues.
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.
Looking good! +1 to Jenn's feedback and then I think this should be good
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 taking care of this one!
f3ca374
to
9d325fa
Compare
9d325fa
to
4c4ab73
Compare
4c4ab73
to
7f5300d
Compare
File metricsSummaryTotal size: 3.94 MB*
Detailsbutton
* Results are not gzipped or minified. * An ASCII character in UTF-8 is 8 bits or 1 byte. |
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.
A couple notes but looking great!
.spectrum-Button--staticWhite { | ||
--spectrum-button-focus-indicator-color: var(--mod-static-black-focus-indicator-color, var(--spectrum-static-black-focus-indicator-color)); | ||
} | ||
|
||
.spectrum-Button--staticBlack { | ||
--spectrum-button-focus-indicator-color: var(--mod-static-black-focus-indicator-color, var(--spectrum-static-black-focus-indicator-color)); | ||
} |
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.
Do these 2 need increased specificity by incorporating the .spectrum-Button selector as well?
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 don't think so, unless there's a scenario you're thinking of? I just moved these up a tiny bit above the high contrast styles. They are still at the end of the file and override the same specificity of their definitions in .spectrum-Button
.
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.
We can't rely on order for apply styles appropriately because a lot of processing moves things around. Just raising the question because I've seen a few components where insufficient specificity was causing styles not to be applied after processing.
7ace8d0
to
49ba01d
Compare
This was marked as do-not-merge until the issue with UI Icons vs Workflow icons can be addressed. Per discussions, design intends Workflow icons to be used with Button, but without documentation/guidelines in place for that, it's guaranteed that buttons are currently in use that use UI icons. Including one of the demoed pagination examples using Splitbutton with the chevron, that was caught in the VRTs. Storybook currently allows selecting any icon for Button, and the following examples show the difference in the vertical alignment of the icon. This results from the token for spacing above the icon accounting for a fixed Workflow icon size, whereas UI Icons are various sizes: Once Icon is migrated to core tokens (in progress) and has a custom property for its size, this can be addressed to support both icon types with a CSS calc and/or min/max. |
e111b4e
to
1a3df2a
Compare
This is ready for re-review. Storybook is updated and has a Chromatic-only template. I've updated the styles to support existing use of UI icons instead of Workflow icons to address my last comment, and have added some more explanation in the PR description. I'm wondering if the alignment change should be marked as a breaking change. Or if it would be better to save that part of the change for Spectrum 2 ( @pfulton )? |
I'm inclined to make it a breaking change and introduce it now. |
b6bbbd8
to
bf3688d
Compare
28e2929
to
574a34f
Compare
@@ -15,7 +15,7 @@ | |||
}, | |||
"main": "dist/index-vars.css", | |||
"peerDependencies": { | |||
"@spectrum-css/icon": ">=4", | |||
"@spectrum-css/icon": ">=6", |
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 capturing this requirement update!
}, | ||
layout: { | ||
name: "Layout", | ||
description: "How the buttons align in the preview (Storybook only).", |
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.
Just noting here that this will probably no longer be necessary after the storybook layout decorator merges - plus side, I might steal this approach for that PR #2420!
574a34f
to
e84b131
Compare
5a820f8
to
a517b27
Compare
Remove the CSS that prevents the text in the button from wrapping. The guidelines for the component say "When the button text is too long for the horizontal space available, it wraps to form another line."
Add "Wrapping" story that demonstrates a button with long text that wraps to the next line. Some template adjustments and additional args added to allow for this.
BREAKING CHANGE: changes vertical flex alignment to start. Previously when the button had an icon and the text was wrapping, the icon was vertically aligned center and the text was aligned center. This fixes this to match with the design spec: for the version of the button that uses a workflow icon, the icon should stay aligned to the top, and the text should be aligned left (start). This uses the defined token for the space between the top of the component and the workflow icon (--spectrum-component-top-to-workflow-icon-*).
Rename Storybook control for stacking buttons to "layout" with specified options, which is a more appropriate name. The control has also been made visible.
Support any existing use of ui icons with the updated wrapping behavior. And add Chromatic only testing of them to the Wrapping story. Workflow icons are intended, with the use of the spectrum-component-top-to-workflow-icon tokens, but UI icons have not yet been specifically excluded in guidelines and are currently in use within SplitButton in this library. This keeps UI icons that are smaller than the intended workflow icon, better vertically centered with the text within the button.
Add a mod property to make it easy to modify the margin-block-start of the icon, in case of alignment issues with icons that are not the intended workflow sizes.
a517b27
to
c81a6f2
Compare
FYI this one caught us by surprise over in Project X, we got unexpectedly wrapping buttons and misaligned icons! We're disabling this wrapping behavior by default as it introduces bugs and putting it behind a |
Description
This update allows text wrapping within the Button component and updates the alignment of the label and icon when wrapping to conform with the design specs.
Fixes a previously introduced bug that disabled wrapping of lengthy text inside a Button. This removes the white-space property that prevented wrapping.
BREAKING CHANGE: Updates styles so that buttons that contain a workflow icon have the correct icon and text alignment. Previously everything was vertically aligned center and the text was aligned center, which did not match the design in the case of wrapping text. See screenshots for reference to the design.
This is a significant change as the vertical flex alignment of the icon is now to the top/start instead of the center, and the design defined --spectrum-component-top-to-workflow-icon-* tokens are used for the spacing between the icon and the top of the component. While button is intended to be used with workflow icons, there were not previously any guidelines around not using UI icons and even SplitButton was using one---in order to support vertical alignment of any existing usage of UI icons, some additional CSS calculations were included to add some margin based on the difference between the height of the intended workflow icon size and the actual icon size used (now accessible through
--spectrum-icon-block-size
since the 6.0 core tokens migration of Icon).Adds a "Wrapping" example to Storybook. This also has a Chromatic-only version with additional variations displayed.
CSS-621
How and where has this been tested?
Please tag yourself on the tests you've marked complete to confirm the tests have been run by someone other than the author.
Validation steps
Regression testing
Validate:
Screenshots
Updated wrapping behavior (Storybook):

Chromatic view of Wrapping story that includes showing backwards compatible alignment of differently sized UI icons

Reference: design spec for wrapping behavior with icon


Previous behavior:
Reference: design spec for wrapping behavior without icon

To-do list