Skip to content

Commit 3383b26

Browse files
committed
fix(button): icon alignment when text is wrapping
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-*).
1 parent f49ee9a commit 3383b26

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

components/button/index.css

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ governing permissions and limitations under the License.
2525
--spectrum-button-focus-indicator-color: var(--spectrum-focus-indicator-color);
2626
}
2727

28-
2928
.spectrum-Button--sizeS {
3029
--spectrum-button-min-width: calc(var(--spectrum-component-height-75) * var(--spectrum-button-minimum-width-multiplier));
3130

@@ -40,6 +39,7 @@ governing permissions and limitations under the License.
4039
--spectrum-button-padding-label-to-icon: var(--spectrum-text-to-visual-75);
4140
--spectrum-button-top-to-text: var(--spectrum-button-top-to-text-small);
4241
--spectrum-button-bottom-to-text: var(--spectrum-button-bottom-to-text-small);
42+
--spectrum-button-top-to-icon: var(--spectrum-component-top-to-workflow-icon-75);
4343
}
4444

4545
.spectrum-Button--sizeM {
@@ -56,6 +56,7 @@ governing permissions and limitations under the License.
5656
--spectrum-button-padding-label-to-icon: var(--spectrum-text-to-visual-100);
5757
--spectrum-button-top-to-text: var(--spectrum-button-top-to-text-medium);
5858
--spectrum-button-bottom-to-text: var(--spectrum-button-bottom-to-text-medium);
59+
--spectrum-button-top-to-icon: var(--spectrum-component-top-to-workflow-icon-100);
5960
}
6061

6162
.spectrum-Button--sizeL {
@@ -72,6 +73,7 @@ governing permissions and limitations under the License.
7273
--spectrum-button-padding-label-to-icon: var(--spectrum-text-to-visual-200);
7374
--spectrum-button-top-to-text: var(--spectrum-button-top-to-text-large);
7475
--spectrum-button-bottom-to-text: var(--spectrum-button-bottom-to-text-large);
76+
--spectrum-button-top-to-icon: var(--spectrum-component-top-to-workflow-icon-200);
7577
}
7678

7779
.spectrum-Button--sizeXL {
@@ -88,7 +90,7 @@ governing permissions and limitations under the License.
8890
--spectrum-button-padding-label-to-icon: var(--spectrum-text-to-visual-300);
8991
--spectrum-button-top-to-text: var(--spectrum-button-top-to-text-extra-large);
9092
--spectrum-button-bottom-to-text: var(--spectrum-button-bottom-to-text-extra-large);
91-
93+
--spectrum-button-top-to-icon: var(--spectrum-component-top-to-workflow-icon-300);
9294
}
9395

9496
.spectrum-Button {
@@ -121,12 +123,17 @@ governing permissions and limitations under the License.
121123
}
122124

123125
.spectrum-Icon {
126+
margin-block-start: max(0px,
127+
var(--mod-button-top-to-icon, var(--spectrum-button-top-to-icon)) -
128+
var(--mod-button-border-width, var(--spectrum-button-border-width))
129+
);
124130
margin-inline-start: calc(
125131
var(--mod-button-edge-to-visual, var(--spectrum-button-edge-to-visual)) -
126132
var(--mod-button-edge-to-text, var(--spectrum-button-edge-to-text))
127133
);
128134
color: inherit;
129135
flex-shrink: 0;
136+
align-self: flex-start;
130137
}
131138

132139
/* correct focus indicator radius for t-shirt sizing */
@@ -141,6 +148,7 @@ governing permissions and limitations under the License.
141148

142149
.spectrum-Icon {
143150
margin-inline-start: 0;
151+
margin-block-start: 0;
144152
}
145153

146154
&::after {
@@ -159,6 +167,11 @@ a.spectrum-Button {
159167
padding-block-end: calc(var(--mod-button-bottom-to-text, var(--spectrum-button-bottom-to-text)) - var(--mod-button-border-width, var(--spectrum-button-border-width)));
160168
line-height: var(--mod-button-line-height, var(--spectrum-button-line-height));
161169
align-self: start;
170+
text-align: var(--mod-button-text-align, center);
171+
}
172+
173+
.spectrum-Button .spectrum-Icon + .spectrum-Button-label {
174+
text-align: var(--mod-button-text-align-with-icon, start);
162175
}
163176

164177
.spectrum-Button {
@@ -170,26 +183,22 @@ a.spectrum-Button {
170183
}
171184
}
172185

173-
/* special cases for focus-ring */
186+
/* Special cases for focus indicator */
174187
.spectrum-Button {
175188
transition: border-color var(--mod-button-animation-duration, var(--spectrum-button-animation-duration)) ease-in-out;
176189

177190
&::after {
178191
position: absolute;
179192
inset: 0;
180-
181193
margin: calc((var(--mod-button-focus-ring-gap, var(--spectrum-button-focus-ring-gap)) + var(--mod-button-border-width, var(--spectrum-button-border-width))) * -1);
182-
183194
border-radius: var(--mod-button-focus-ring-border-radius, var(--spectrum-button-focus-ring-border-radius));
184-
185195
transition: box-shadow var(--mod-button-animation-duration, var(--spectrum-button-animation-duration)) ease-in-out;
186-
187196
pointer-events: none;
188197
content: '';
189198
}
190199

191200
&:focus-visible {
192-
/* kill the default ring */
201+
/* Remove the default focus outline */
193202
box-shadow: none;
194203
outline: none;
195204

@@ -202,7 +211,6 @@ a.spectrum-Button {
202211

203212
/* Core Token Theming */
204213
/* former skin.css, applied / copied from actionbutton/index.css */
205-
206214
.spectrum-Button {
207215
@inherit: %spectrum-BaseButton;
208216

@@ -236,7 +244,16 @@ a.spectrum-Button {
236244
}
237245
}
238246

239-
/* windows high contrast mode over-writes for accent variant */
247+
/* Static color variants */
248+
.spectrum-Button--staticWhite {
249+
--spectrum-button-focus-indicator-color: var(--mod-static-black-focus-indicator-color, var(--spectrum-static-black-focus-indicator-color));
250+
}
251+
252+
.spectrum-Button--staticBlack {
253+
--spectrum-button-focus-indicator-color: var(--mod-static-black-focus-indicator-color, var(--spectrum-static-black-focus-indicator-color));
254+
}
255+
256+
/* Windows High Contrast Mode */
240257
@media (forced-colors: active) {
241258
.spectrum-Button {
242259
--highcontrast-button-content-color-disabled: GrayText;
@@ -267,12 +284,3 @@ a.spectrum-Button {
267284
}
268285
}
269286
}
270-
271-
/* static variants */
272-
.spectrum-Button--staticWhite {
273-
--spectrum-button-focus-indicator-color: var(--mod-static-black-focus-indicator-color, var(--spectrum-static-black-focus-indicator-color));
274-
}
275-
276-
.spectrum-Button--staticBlack {
277-
--spectrum-button-focus-indicator-color: var(--mod-static-black-focus-indicator-color, var(--spectrum-static-black-focus-indicator-color));
278-
}

components/button/metadata/mods.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
| `--mod-button-margin-right` |
3636
| `--mod-button-min-width` |
3737
| `--mod-button-padding-label-to-icon` |
38+
| `--mod-button-text-align` |
39+
| `--mod-button-text-align-with-icon` |
40+
| `--mod-button-top-to-icon` |
3841
| `--mod-button-top-to-text` |
3942
| `--mod-focus-indicator-gap` |
4043
| `--mod-static-black-focus-indicator-color` |

components/button/stories/button.stories.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ export default {
7070
control: "boolean",
7171
},
7272
staticColor: {
73-
name: "StaticColor",
73+
name: "Static Color",
74+
description: "Variants that can be used when a button needs to be placed on top of a colored background or a visual.",
7475
type: { name: "string" },
7576
table: {
7677
type: { summary: "string" },
@@ -79,6 +80,15 @@ export default {
7980
options: ["white", "black"],
8081
control: "select",
8182
},
83+
backgroundColor: {
84+
name: "Parent Background Color",
85+
description: "Background color of the button's parent element in Storybook. For testing the 'Static Color' variants.",
86+
type: { name: "string" },
87+
table: {
88+
type: { summary: "string" },
89+
category: "Advanced",
90+
},
91+
},
8292
showIconOnlyButton: {
8393
table: {
8494
disable: true,

0 commit comments

Comments
 (0)