Skip to content

Commit e4bf910

Browse files
committed
feat(actionmenu): migrate to s2 tokens and styling
1 parent 9601a89 commit e4bf910

File tree

23 files changed

+1115
-648
lines changed

23 files changed

+1115
-648
lines changed

components/actionbutton/dist/metadata.json

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,16 @@
1414
".spectrum-ActionButton-label",
1515
".spectrum-ActionButton-label:empty",
1616
".spectrum-ActionButton.is-disabled",
17-
".spectrum-ActionButton.is-selected",
18-
".spectrum-ActionButton.is-selected.spectrum-ActionButton--emphasized",
19-
".spectrum-ActionButton.is-selected.spectrum-ActionButton--staticBlack",
20-
".spectrum-ActionButton.is-selected.spectrum-ActionButton--staticWhite",
17+
".spectrum-ActionButton.spectrum-ActionButton--emphasized:where(.is-selected, [aria-pressed=\"true\"], [aria-expanded=\"true\"])",
2118
".spectrum-ActionButton.spectrum-ActionButton--quiet",
22-
".spectrum-ActionButton.spectrum-ActionButton--quiet.is-selected",
23-
".spectrum-ActionButton.spectrum-ActionButton--quiet:disabled:not(.is-selected)",
19+
".spectrum-ActionButton.spectrum-ActionButton--quiet:where(.is-selected, [aria-pressed=\"true\"], [aria-expanded=\"true\"])",
20+
".spectrum-ActionButton.spectrum-ActionButton--quiet:where(:disabled, .is-disabled, [aria-disabled=\"true\"]):not(:where(.is-selected, [aria-pressed=\"true\"], [aria-expanded=\"true\"]))",
2421
".spectrum-ActionButton.spectrum-ActionButton--staticBlack",
2522
".spectrum-ActionButton.spectrum-ActionButton--staticBlack.spectrum-ActionButton--quiet",
23+
".spectrum-ActionButton.spectrum-ActionButton--staticBlack:where(.is-selected, [aria-pressed=\"true\"], [aria-expanded=\"true\"])",
2624
".spectrum-ActionButton.spectrum-ActionButton--staticWhite",
2725
".spectrum-ActionButton.spectrum-ActionButton--staticWhite.spectrum-ActionButton--quiet",
26+
".spectrum-ActionButton.spectrum-ActionButton--staticWhite:where(.is-selected, [aria-pressed=\"true\"], [aria-expanded=\"true\"])",
2827
".spectrum-ActionButton::-moz-focus-inner",
2928
".spectrum-ActionButton:active",
3029
".spectrum-ActionButton:after",
@@ -36,10 +35,11 @@
3635
".spectrum-ActionButton:has(.spectrum-ActionButton-icon)",
3736
".spectrum-ActionButton:hover",
3837
".spectrum-ActionButton:not(:has(.spectrum-ActionButton-label))",
38+
".spectrum-ActionButton:where(.is-selected, [aria-pressed=\"true\"], [aria-expanded=\"true\"])",
39+
".spectrum-ActionButton:where(:disabled, .is-disabled, [aria-disabled=\"true\"])",
3940
"a.spectrum-ActionButton"
4041
],
4142
"modifiers": [
42-
"--mod-actionbutton-animation-duration",
4343
"--mod-actionbutton-background-color-default",
4444
"--mod-actionbutton-background-color-default-selected",
4545
"--mod-actionbutton-background-color-default-selected-emphasized",
@@ -71,10 +71,6 @@
7171
"--mod-actionbutton-edge-to-text",
7272
"--mod-actionbutton-edge-to-visual",
7373
"--mod-actionbutton-edge-to-visual-only",
74-
"--mod-actionbutton-focus-indicator-border-radius",
75-
"--mod-actionbutton-focus-indicator-color",
76-
"--mod-actionbutton-focus-indicator-gap",
77-
"--mod-actionbutton-focus-indicator-thickness",
7874
"--mod-actionbutton-font-size",
7975
"--mod-actionbutton-font-style",
8076
"--mod-actionbutton-font-weight",

components/actionbutton/index.css

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ governing permissions and limitations under the License.
6363
--spectrum-actionbutton-background-color-focus: var(--spectrum-gray-200);
6464
--spectrum-actionbutton-background-color-disabled: transparent;
6565

66-
&.is-selected {
66+
&:where(.is-selected, [aria-pressed="true"], [aria-expanded="true"]) {
6767
--spectrum-actionbutton-background-color-disabled: var(--spectrum-disabled-background-color);
6868
}
6969
}
@@ -116,7 +116,8 @@ governing permissions and limitations under the License.
116116
}
117117
}
118118

119-
&.is-selected {
119+
/* expanded is specific to action menu when the menu is open */
120+
&:where(.is-selected, [aria-pressed="true"], [aria-expanded="true"]) {
120121
--mod-actionbutton-background-color-default: var(--mod-actionbutton-background-color-default-selected, var(--spectrum-neutral-background-color-selected-default));
121122
--mod-actionbutton-background-color-hover: var(--mod-actionbutton-background-color-hover-selected, var(--spectrum-neutral-background-color-selected-hover));
122123
--mod-actionbutton-background-color-down: var(--mod-actionbutton-background-color-down-selected, var(--spectrum-neutral-background-color-selected-down));
@@ -298,6 +299,16 @@ governing permissions and limitations under the License.
298299
border-style: none;
299300
}
300301

302+
&::after {
303+
position: absolute;
304+
inset: 0;
305+
margin: calc((var(--spectrum-actionbutton-focus-indicator-gap) + var(--spectrum-actionbutton-border-width)) * -1);
306+
border-radius: var(--spectrum-actionbutton-focus-indicator-border-radius);
307+
transition: box-shadow var(--highcontrast-actionbutton-animation-duration, var(--spectrum-actionbutton-animation-duration)) ease-in-out;
308+
pointer-events: none;
309+
content: "";
310+
}
311+
301312
&:focus {
302313
outline: none;
303314
}
@@ -315,6 +326,13 @@ governing permissions and limitations under the License.
315326
&:focus-visible {
316327
background-color: var(--highcontrast-actionbutton-background-color-default, var(--mod-actionbutton-background-color-focus, var(--spectrum-actionbutton-background-color-focus)));
317328
color: var(--highcontrast-actionbutton-content-color-default, var(--mod-actionbutton-content-color-focus, var(--spectrum-actionbutton-content-color-focus)));
329+
330+
box-shadow: none;
331+
outline: none;
332+
333+
&::after {
334+
box-shadow: 0 0 0 var(--spectrum-actionbutton-focus-indicator-thickness) var(--highcontrast-actionbutton-focus-indicator-color, var(--spectrum-actionbutton-focus-indicator-color));
335+
}
318336
}
319337

320338
&:active {
@@ -323,8 +341,8 @@ governing permissions and limitations under the License.
323341
transform: perspective(var(--spectrum-actionbutton-downstate-perspective)) translateZ(var(--spectrum-component-size-difference-down));
324342
}
325343

326-
&:disabled,
327-
&.is-disabled {
344+
/* ideal when we want to disable the button but still allow it's content to be focused */
345+
&:where(:disabled, .is-disabled, [aria-disabled="true"]) {
328346
background-color: var(--highcontrast-actionbutton-background-color-disabled, var(--mod-actionbutton-background-color-disabled, var(--spectrum-actionbutton-background-color-disabled)));
329347
color: var(--highcontrast-actionbutton-content-color-disabled, var(--mod-actionbutton-content-color-disabled, var(--spectrum-actionbutton-content-color-disabled)));
330348
}
@@ -364,10 +382,6 @@ a.spectrum-ActionButton {
364382
/* Fixes horizontal alignment of text in anchor buttons */
365383
text-align: center;
366384

367-
&:empty {
368-
display: none;
369-
}
370-
371385
pointer-events: none;
372386

373387
font-size: var(--mod-actionbutton-font-size, var(--spectrum-actionbutton-font-size));
@@ -378,40 +392,21 @@ a.spectrum-ActionButton {
378392

379393
text-overflow: ellipsis;
380394
overflow: hidden;
395+
396+
&:empty {
397+
display: none;
398+
}
381399
}
382400

383401
.spectrum-ActionButton-hold {
384402
position: absolute;
385403
inset-inline-end: calc(var(--mod-actionbutton-edge-to-hold-icon, var(--spectrum-actionbutton-edge-to-hold-icon)) - var(--spectrum-actionbutton-border-width));
386404
inset-block-end: calc(var(--mod-actionbutton-edge-to-hold-icon, var(--spectrum-actionbutton-edge-to-hold-icon)) - var(--spectrum-actionbutton-border-width));
405+
display: block;
387406
color: inherit;
388407
transform: var(--spectrum-logical-rotation);
389408
}
390409

391-
/* Focus indicator */
392-
.spectrum-ActionButton {
393-
transition: border-color var(--highcontrast-actionbutton-animation-duration, var(--mod-actionbutton-animation-duration, var(--spectrum-actionbutton-animation-duration))) ease-in-out;
394-
395-
&::after {
396-
position: absolute;
397-
inset: 0;
398-
margin: calc((var(--mod-actionbutton-focus-indicator-gap, var(--spectrum-actionbutton-focus-indicator-gap)) + var(--spectrum-actionbutton-border-width)) * -1);
399-
border-radius: var(--mod-actionbutton-focus-indicator-border-radius, var(--spectrum-actionbutton-focus-indicator-border-radius));
400-
transition: box-shadow var(--highcontrast-actionbutton-animation-duration, var(--mod-actionbutton-animation-duration, var(--spectrum-actionbutton-animation-duration))) ease-in-out;
401-
pointer-events: none;
402-
content: "";
403-
}
404-
405-
&:focus-visible {
406-
box-shadow: none;
407-
outline: none;
408-
409-
&::after {
410-
box-shadow: 0 0 0 var(--mod-actionbutton-focus-indicator-thickness, var(--spectrum-actionbutton-focus-indicator-thickness)) var(--highcontrast-actionbutton-focus-indicator-color, var(--mod-actionbutton-focus-indicator-color, var(--spectrum-actionbutton-focus-indicator-color)));
411-
}
412-
}
413-
}
414-
415410
@media (forced-colors: active) {
416411
.spectrum-ActionButton {
417412
/**
@@ -457,7 +452,7 @@ a.spectrum-ActionButton {
457452
--highcontrast-actionbutton-background-color-disabled: Canvas;
458453
--highcontrast-actionbutton-content-color-default: CanvasText;
459454

460-
&:disabled:not(.is-selected) {
455+
&:where(:disabled, .is-disabled, [aria-disabled="true"]):not(:where(.is-selected, [aria-pressed="true"], [aria-expanded="true"])) {
461456
--highcontrast-actionbutton-border-color: Canvas;
462457
}
463458
}
@@ -469,8 +464,7 @@ a.spectrum-ActionButton {
469464
--highcontrast-actionbutton-border-color: Highlight;
470465
}
471466

472-
/* Selected always shows as a solid highlighted color. */
473-
&.is-selected {
467+
&:where(.is-selected, [aria-pressed="true"], [aria-expanded="true"]) {
474468
--highcontrast-actionbutton-border-color: Highlight;
475469
--highcontrast-actionbutton-background-color-default: Highlight;
476470
--highcontrast-actionbutton-content-color-default: HighlightText;

components/actionbutton/stories/actionbutton.stories.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { default as IconStories } from "@spectrum-css/icon/stories/icon.stories.js";
22
import { Sizes, withDownStateDimensionCapture } from "@spectrum-css/preview/decorators";
33
import { disableDefaultModes } from "@spectrum-css/preview/modes";
4-
import { isActive, isDisabled, isEmphasized, isFocused, isHovered, isQuiet, isSelected, size, staticColor } from "@spectrum-css/preview/types";
5-
import metadata from "../dist/metadata.json";
6-
import packageJson from "../package.json";
4+
import { isActive, isDisabled, isEmphasized, isFocused, isHovered, isOpen, isQuiet, isSelected, size, staticColor } from "@spectrum-css/preview/types";
75
import { ActionButtonGroup } from "./actionbutton.test.js";
86
import { ActionButtonsWithIconOptions, IconOnlyOption, Template, TreatmentTemplate } from "./template.js";
97

8+
// Local assets to render the component styles and structure
9+
import metadata from "../dist/metadata.json";
10+
import packageJson from "../package.json";
11+
1012
/**
1113
* The action button component represents an action a user can take.
1214
*
@@ -56,8 +58,8 @@ export default {
5658
control: "boolean",
5759
},
5860
hasPopup: {
59-
name: "Has popup",
60-
description: "If the button triggers a popup action, this should be set to reflect the type of element that pops-up.",
61+
name: "Has pop-up",
62+
description: "If the button triggers a pop-up action, this should be set to reflect the type of element that pops-up.",
6163
type: { name: "string" },
6264
table: {
6365
type: { summary: "string" },
@@ -66,6 +68,22 @@ export default {
6668
control: "select",
6769
options: ["true", "menu", "listbox", "tree", "grid", "dialog", "false"],
6870
},
71+
hasLongPress: {
72+
name: "Long press",
73+
description: "If the trigger supports a long-press action which triggers the menu, this should be set to true.",
74+
type: { name: "boolean" },
75+
table: {
76+
type: { summary: "boolean" },
77+
category: "Accessibility",
78+
},
79+
control: "boolean",
80+
},
81+
isOpen: {
82+
...isOpen,
83+
name: "Pop-up is open",
84+
description: "When the button triggers a pop-up, this should be true when the pop-up is open.",
85+
if: { arg: "hasPopup", truthy: true },
86+
},
6987
staticColor: {
7088
...staticColor,
7189
if: { arg: "isEmphasized", truthy: false },
@@ -77,6 +95,7 @@ export default {
7795
isQuiet: false,
7896
isEmphasized: false,
7997
hasPopup: "false",
98+
hasLongPress: false,
8099
isActive: false,
81100
isFocused: false,
82101
isHovered: false,

components/actionbutton/stories/actionbutton.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ export const ActionButtons = (args, context) => {
1717
${Template({
1818
...args,
1919
hasPopup: "true",
20+
hasLongPress: true,
2021
hideLabel: true,
2122
}, context)}
2223
${Template({
2324
...args,
2425
iconName: undefined,
2526
hasPopup: "true",
27+
hasLongPress: true,
2628
}, context)}
2729
</div>
2830
`;

components/actionbutton/stories/template.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ export const Template = ({
5454
isFocused = false,
5555
isActive = false,
5656
isDisabled = false,
57+
isOpen = false,
5758
hasPopup = "false",
59+
hasLongPress = false,
5860
popupId,
5961
hideLabel = false,
6062
staticColor,
@@ -72,7 +74,8 @@ export const Template = ({
7274
aria-label=${ifDefined(hideLabel ? label : undefined)}
7375
aria-haspopup=${ifDefined(hasPopup && hasPopup !== "false" ? hasPopup : undefined)}
7476
aria-controls=${hasPopup && hasPopup !== "false" ? popupId : undefined}
75-
aria-pressed=${isSelected ? "true" : "false"}
77+
aria-pressed=${ifDefined(isSelected ? "true" : undefined)}
78+
aria-expanded=${ifDefined(hasPopup && hasPopup !== "false" ? isOpen ? "true" : "false" : undefined)}
7679
class=${classMap({
7780
[rootClass]: true,
7881
[`${rootClass}--size${size?.toUpperCase()}`]:
@@ -82,14 +85,14 @@ export const Template = ({
8285
[`${rootClass}--static${capitalize(staticColor)}`]:
8386
typeof staticColor !== "undefined",
8487
["is-disabled"]: isDisabled,
85-
["is-selected"]: isSelected,
8688
["is-hover"]: isHovered,
8789
["is-focus-visible"]: isFocused,
8890
["is-active"]: isActive,
8991
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
9092
})}
9193
id=${id}
9294
data-testid=${testId ?? id}
95+
popovertarget=${ifDefined(hasPopup && hasPopup !== "false" ? popupId : undefined)}
9396
role=${ifDefined(role)}
9497
style=${styleMap(customStyles)}
9598
?disabled=${isDisabled}
@@ -105,7 +108,7 @@ export const Template = ({
105108
updateArgs({ isFocused: false });
106109
}}
107110
>
108-
${when(hasPopup && hasPopup !== "false", () =>
111+
${when(hasLongPress && hasPopup && hasPopup !== "false", () =>
109112
Icon({
110113
size,
111114
iconName: "CornerTriangle" + ({
@@ -138,7 +141,7 @@ export const Template = ({
138141

139142
/**
140143
* Displays multiple action buttons in a row, with different combinations of
141-
* label, icon, and hold button (has popup).
144+
* label, icon, and hold button (has pop-up).
142145
*/
143146
export const ActionButtonsWithIconOptions = (args, context) => Container({
144147
withBorder: false,
@@ -162,19 +165,21 @@ export const ActionButtonsWithIconOptions = (args, context) => Container({
162165
...args,
163166
hideLabel: true,
164167
hasPopup: "true",
168+
hasLongPress: true,
165169
}, context),
166170
Template({
167171
...args,
168172
iconName: undefined,
169173
hasPopup: "true",
174+
hasLongPress: true,
170175
}, context)
171176
],
172177
}, context);
173178

174179
/**
175180
* Displays two action buttons in a row:
176181
* - icon only action button
177-
* - icon only action button with hold button (has popup)
182+
* - icon only action button with hold button (has pop-up)
178183
*/
179184
export const IconOnlyOption = (args, context) => Container({
180185
withBorder: false,
@@ -187,12 +192,14 @@ export const IconOnlyOption = (args, context) => Container({
187192
...args,
188193
hideLabel: true,
189194
hasPopup: "true",
195+
hasLongPress: true,
190196
}, context),
191197
Template({
192198
...args,
193199
hideLabel: true,
194200
isQuiet: true,
195201
hasPopup: "true",
202+
hasLongPress: true,
196203
}, context),
197204
],
198205
}, context);

components/actiongroup/dist/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
".spectrum-ActionGroup--compact:not(.spectrum-ActionGroup--quiet) .spectrum-ActionGroup-item",
1515
".spectrum-ActionGroup--compact:not(.spectrum-ActionGroup--quiet) .spectrum-ActionGroup-item + .spectrum-ActionGroup-item",
1616
".spectrum-ActionGroup--compact:not(.spectrum-ActionGroup--quiet) .spectrum-ActionGroup-item .spectrum-ActionButton-label",
17-
".spectrum-ActionGroup--compact:not(.spectrum-ActionGroup--quiet) .spectrum-ActionGroup-item.is-selected",
1817
".spectrum-ActionGroup--compact:not(.spectrum-ActionGroup--quiet) .spectrum-ActionGroup-item:first-child",
1918
".spectrum-ActionGroup--compact:not(.spectrum-ActionGroup--quiet) .spectrum-ActionGroup-item:focus-visible",
2019
".spectrum-ActionGroup--compact:not(.spectrum-ActionGroup--quiet) .spectrum-ActionGroup-item:hover",
2120
".spectrum-ActionGroup--compact:not(.spectrum-ActionGroup--quiet) .spectrum-ActionGroup-item:last-child",
21+
".spectrum-ActionGroup--compact:not(.spectrum-ActionGroup--quiet) .spectrum-ActionGroup-item:where(.is-selected, [aria-pressed=\"true\"], [aria-expanded=\"true\"])",
2222
".spectrum-ActionGroup--justified .spectrum-ActionGroup-item",
2323
".spectrum-ActionGroup--sizeL",
2424
".spectrum-ActionGroup--sizeM",

components/actiongroup/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
margin-inline-end: var(--mod-actiongroup-border-radius-reset, var(--spectrum-actiongroup-border-radius-reset));
103103
}
104104

105-
&.is-selected {
105+
&:where(.is-selected, [aria-pressed="true"], [aria-expanded="true"]) {
106106
z-index: 1;
107107
}
108108

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"sourceFile": "index.css",
3+
"selectors": [".spectrum-ActionMenu", ".spectrum-ActionMenu-popover"],
4+
"modifiers": ["--mod-actionmenu-button-to-menu-gap"],
5+
"component": ["--spectrum-actionmenu-button-to-menu-gap"],
6+
"global": ["--spectrum-spacing-100"],
7+
"passthroughs": ["--mod-popover-animation-distance"],
8+
"high-contrast": []
9+
}

0 commit comments

Comments
 (0)