Skip to content

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

Merged
merged 6 commits into from
Feb 20, 2024

Conversation

jawinn
Copy link
Collaborator

@jawinn jawinn commented Oct 31, 2023

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

  • Verify changes with design team [@jawinn]
  • Button wrapping example exists in Storybook.
  • Button without icon wraps and has centered text (like guidelines).
  • Button with icon has icon aligned to the top of the component and text aligned to the left/start of the component. Matching "Design spec for wrapping behavior with icon" in screenshots.
  • Wrapping behavior looks correct in right-to-left text direction.
  • Non-wrapping examples of the button with an icon have no visual changes.

Regression testing

Validate:

  1. A legacy documentation page (such as accordion), including:
  • The page renders correctly
  • The page is accessible
  • The page is responsive
  1. A migrated documentation page (such as action group), including:
  • The page renders correctly
  • The page is accessible
  • The page is responsive

Screenshots

Updated wrapping behavior (Storybook):
Screenshot 2023-10-31 at 3 48 35 PM

Chromatic view of Wrapping story that includes showing backwards compatible alignment of differently sized UI icons
Screenshot 2024-02-08 at 11 57 21 AM

Reference: design spec for wrapping behavior with icon
Screenshot 2023-10-31 at 4 02 40 PM
Previous behavior:
Screenshot 2024-02-08 at 2 14 28 PM

Reference: design spec for wrapping behavior without icon
button_behaviors_text-overflow@2x_1649295070805

To-do list

  • I have read the contribution guidelines.
  • I have updated relevant storybook stories and templates.
  • I have tested these changes in Windows High Contrast mode.
  • If my change impacts documentation, I have updated the documentation accordingly.
  • VRTs have been run and reviewed.
  • ✨ This pull request is ready to merge. ✨

@jawinn jawinn force-pushed the jawinn/css-621-button-wrapping-text branch from 3383b26 to e28f7b7 Compare October 31, 2023 20:00
Copy link
Contributor

github-actions bot commented Oct 31, 2023

🚀 Deployed on https://pr-2248--spectrum-css.netlify.app

@github-actions github-actions bot temporarily deployed to pull request October 31, 2023 20:05 Inactive
@jawinn jawinn force-pushed the jawinn/css-621-button-wrapping-text branch from e28f7b7 to eebd23f Compare October 31, 2023 20:14
@github-actions github-actions bot temporarily deployed to pull request October 31, 2023 20:20 Inactive
@jawinn jawinn added the run_vrt For use on PRs looking to kick off VRT label Oct 31, 2023
@github-actions github-actions bot removed the run_vrt For use on PRs looking to kick off VRT label Oct 31, 2023
Copy link
Contributor

@jenndiaz jenndiaz left a 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.

Copy link
Collaborator

@mdt2 mdt2 left a 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

@github-actions github-actions bot temporarily deployed to pull request November 1, 2023 21:43 Inactive
@jawinn jawinn requested a review from jenndiaz November 1, 2023 21:53
Copy link
Collaborator

@pfulton pfulton left a 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!

@castastrophe castastrophe force-pushed the jawinn/css-621-button-wrapping-text branch from f3ca374 to 9d325fa Compare November 3, 2023 18:34
@github-actions github-actions bot temporarily deployed to pull request November 3, 2023 18:40 Inactive
@jawinn jawinn force-pushed the jawinn/css-621-button-wrapping-text branch from 9d325fa to 4c4ab73 Compare November 8, 2023 21:27
@github-actions github-actions bot temporarily deployed to pull request November 8, 2023 21:33 Inactive
@jawinn jawinn added the run_vrt For use on PRs looking to kick off VRT label Nov 8, 2023
@github-actions github-actions bot removed the run_vrt For use on PRs looking to kick off VRT label Nov 8, 2023
@jawinn jawinn force-pushed the jawinn/css-621-button-wrapping-text branch from 4c4ab73 to 7f5300d Compare November 8, 2023 22:14
@github-actions github-actions bot temporarily deployed to pull request November 8, 2023 22:17 Inactive
@jawinn jawinn added the run_vrt For use on PRs looking to kick off VRT label Nov 8, 2023
@github-actions github-actions bot removed the run_vrt For use on PRs looking to kick off VRT label Nov 8, 2023
@jawinn jawinn added the do not merge A flag for a branch indicating it should not be merged. label Nov 9, 2023
Copy link
Contributor

github-actions bot commented Nov 10, 2023

File metrics

Summary

Total size: 3.94 MB*
Total change (Δ): ⬆ 4.39 KB (0.11%)
Table reports on changes to a package's main file. Other changes can be found in the collapsed "Details" below.

Package Size Δ
button 82.35 KB ⬆ 1.42 KB
Details

button

File Head Base Δ
index-base.css 52.40 KB 50.98 KB ⬆ 1.42 KB (2.78%)
index-theme.css 30.53 KB 30.53 KB -
index-vars.css 82.35 KB 80.93 KB ⬆ 1.42 KB (1.75%)
index.css 82.35 KB 80.93 KB ⬆ 1.42 KB (1.75%)
mods.json 1.77 KB 1.63 KB ⬆ 0.15 KB (8.89%)
themes/express.css 29.33 KB 29.33 KB -
themes/spectrum.css 29.71 KB 29.71 KB -
* Size determined by adding together the size of the main file for all packages in the library.
* Results are not gzipped or minified.
* An ASCII character in UTF-8 is 8 bits or 1 byte.

Copy link
Collaborator

@castastrophe castastrophe left a 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!

Comment on lines +249 to +303
.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));
}
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

@jawinn jawinn force-pushed the jawinn/css-621-button-wrapping-text branch from 7ace8d0 to 49ba01d Compare November 16, 2023 16:59
@jawinn
Copy link
Collaborator Author

jawinn commented Nov 21, 2023

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.

@castastrophe castastrophe marked this pull request as draft January 17, 2024 14:17
@jawinn jawinn force-pushed the jawinn/css-621-button-wrapping-text branch from e111b4e to 1a3df2a Compare February 7, 2024 23:23
@jawinn jawinn marked this pull request as ready for review February 8, 2024 19:16
@jawinn
Copy link
Collaborator Author

jawinn commented Feb 8, 2024

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 )?

@jawinn jawinn added ready-for-review and removed do not merge A flag for a branch indicating it should not be merged. labels Feb 9, 2024
@pfulton
Copy link
Collaborator

pfulton commented Feb 14, 2024

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.

@@ -15,7 +15,7 @@
},
"main": "dist/index-vars.css",
"peerDependencies": {
"@spectrum-css/icon": ">=4",
"@spectrum-css/icon": ">=6",
Copy link
Collaborator

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).",
Copy link
Collaborator

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!

@castastrophe castastrophe force-pushed the jawinn/css-621-button-wrapping-text branch from 574a34f to e84b131 Compare February 16, 2024 16:29
@castastrophe castastrophe enabled auto-merge (squash) February 16, 2024 16:35
@castastrophe castastrophe force-pushed the jawinn/css-621-button-wrapping-text branch 3 times, most recently from 5a820f8 to a517b27 Compare February 16, 2024 17:33
@pfulton pfulton removed the run_vrt For use on PRs looking to kick off VRT label Feb 20, 2024
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.
@pfulton pfulton force-pushed the jawinn/css-621-button-wrapping-text branch from a517b27 to c81a6f2 Compare February 20, 2024 18:20
@pfulton pfulton added the run_vrt For use on PRs looking to kick off VRT label Feb 20, 2024
@castastrophe castastrophe merged commit 3f14a86 into main Feb 20, 2024
@castastrophe castastrophe deleted the jawinn/css-621-button-wrapping-text branch February 20, 2024 18:28
@github-actions github-actions bot mentioned this pull request Apr 26, 2024
@lazd
Copy link
Member

lazd commented Jul 31, 2024

FYI this one caught us by surprise over in Project X, we got unexpectedly wrapping buttons and misaligned icons!
image

image

image

We're disabling this wrapping behavior by default as it introduces bugs and putting it behind a [wrap] attribute for the fix. see PR https://git.corp.adobe.com/Horizon/hz/pull/89334

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge run_vrt For use on PRs looking to kick off VRT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants