Skip to content

Commit 49ba01d

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 aab6a67 commit 49ba01d

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

components/button/index.css

Lines changed: 28 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 */
@@ -140,7 +147,9 @@ governing permissions and limitations under the License.
140147
border-radius: 50%;
141148

142149
.spectrum-Icon {
150+
align-self: center;
143151
margin-inline-start: 0;
152+
margin-block-start: 0;
144153
}
145154

146155
&::after {
@@ -159,6 +168,11 @@ a.spectrum-Button {
159168
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)));
160169
line-height: var(--mod-button-line-height, var(--spectrum-button-line-height));
161170
align-self: start;
171+
text-align: var(--mod-button-text-align, center);
172+
}
173+
174+
.spectrum-Button .spectrum-Icon + .spectrum-Button-label {
175+
text-align: var(--mod-button-text-align-with-icon, start);
162176
}
163177

164178
.spectrum-Button {
@@ -170,26 +184,22 @@ a.spectrum-Button {
170184
}
171185
}
172186

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

177191
&::after {
178192
position: absolute;
179193
inset: 0;
180-
181194
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-
183195
border-radius: var(--mod-button-focus-ring-border-radius, var(--spectrum-button-focus-ring-border-radius));
184-
185196
transition: box-shadow var(--mod-button-animation-duration, var(--spectrum-button-animation-duration)) ease-in-out;
186-
187197
pointer-events: none;
188198
content: '';
189199
}
190200

191201
&:focus-visible {
192-
/* kill the default ring */
202+
/* Remove the default focus outline */
193203
box-shadow: none;
194204
outline: none;
195205

@@ -202,7 +212,6 @@ a.spectrum-Button {
202212

203213
/* Core Token Theming */
204214
/* former skin.css, applied / copied from actionbutton/index.css */
205-
206215
.spectrum-Button {
207216
@inherit: %spectrum-BaseButton;
208217

@@ -236,7 +245,16 @@ a.spectrum-Button {
236245
}
237246
}
238247

239-
/* windows high contrast mode over-writes for accent variant */
248+
/* Static color variants */
249+
.spectrum-Button--staticWhite {
250+
--spectrum-button-focus-indicator-color: var(--mod-static-black-focus-indicator-color, var(--spectrum-static-black-focus-indicator-color));
251+
}
252+
253+
.spectrum-Button--staticBlack {
254+
--spectrum-button-focus-indicator-color: var(--mod-static-black-focus-indicator-color, var(--spectrum-static-black-focus-indicator-color));
255+
}
256+
257+
/* Windows High Contrast Mode */
240258
@media (forced-colors: active) {
241259
.spectrum-Button {
242260
--highcontrast-button-content-color-disabled: GrayText;
@@ -267,12 +285,3 @@ a.spectrum-Button {
267285
}
268286
}
269287
}
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export default {
7171
},
7272
staticColor: {
7373
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" },

0 commit comments

Comments
 (0)