Skip to content

Commit 0835cae

Browse files
committed
chore: apply code review feedback awesomeness
1 parent 75c284c commit 0835cae

File tree

7 files changed

+64
-40
lines changed

7 files changed

+64
-40
lines changed

.changeset/brave-bikes-teach.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ Example markup:
4444

4545
Updates `@spectrum-css/menu` styles to align with latest Spectrum 2 design specifications and improve accessibility.
4646

47-
- Focus indicator tokens wired through: width, color, gap/offset, and outline style.
48-
- CJK line-height tokens applied for labels, descriptions, and section headers.
49-
- External link and drill‑in icon sizing variables exposed; thumbnail sizing and alignment refined.
50-
- Forced-colors improvements and readability adjustments.
47+
- Added this not to prevent clash with the `.is-selectable` placement.
5148
- Non-breaking; no class or DOM changes required.
5249

5350
### Action button refinements

components/actionbutton/stories/actionbutton.stories.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export default {
107107
},
108108
parameters: {
109109
actions: {
110-
handles: ["click .spectrum-ActionButton:not([disabled])"],
110+
handles: ["click .spectrum-ActionButton:not([disabled])", "mousedown .spectrum-ActionButton:not([disabled])", "mouseup .spectrum-ActionButton:not([disabled])", "touchstart .spectrum-ActionButton:not([disabled])", "touchend .spectrum-ActionButton:not([disabled])"],
111111
},
112112
design: {
113113
type: "figma",
@@ -198,8 +198,8 @@ Quiet.parameters = {
198198

199199
/**
200200
* An action button can have a hold icon (a small corner triangle). This icon indicates that holding down the action button for a
201-
* short amount of time can reveal a [popover](/docs/components-popover--docs) menu, which can be used, for example, to switch
202-
* between related actions. Note that this popover menu is not demonstrated herethis would be handled by the implementation.
201+
* short amount of time (currently the standard is 300ms) can reveal a [popover](/docs/components-popover--docs) menu, which can be used, for example, to switch
202+
* between related actions. Note that this popover menu is not demonstrated here; this would be handled by the implementation.
203203
* Because of the way padding is calculated, the hold icon must be placed before the workflow icon in the markup.
204204
*/
205205
export const HoldIcon = IconOnlyOption.bind({});

components/actionbutton/stories/template.js

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ export const Template = ({
6969
role = "button",
7070
} = {}, context = {}) => {
7171
const { updateArgs } = context;
72+
73+
// If a custom onclick handler isn't provided, close the popover when clicking outside of the button
74+
if (typeof onclick !== "function") {
75+
document.body.addEventListener("click", function (evt) {
76+
if (evt.target.closest(`.${rootClass}`)) {
77+
return;
78+
}
79+
updateArgs({
80+
isSelected: false,
81+
isOpen: false,
82+
});
83+
});
84+
}
85+
7286
return html`
7387
<button
7488
aria-label=${ifDefined(hideLabel ? label : undefined)}
@@ -77,31 +91,36 @@ export const Template = ({
7791
aria-pressed=${ifDefined(isSelected ? "true" : undefined)}
7892
aria-expanded=${ifDefined(hasPopup && hasPopup !== "false" ? isOpen ? "true" : "false" : undefined)}
7993
class=${classMap({
80-
[rootClass]: true,
81-
[`${rootClass}--size${size?.toUpperCase()}`]:
82-
typeof size !== "undefined",
83-
[`${rootClass}--quiet`]: isQuiet,
84-
[`${rootClass}--emphasized`]: isEmphasized,
85-
[`${rootClass}--static${capitalize(staticColor)}`]:
86-
typeof staticColor !== "undefined",
87-
["is-disabled"]: isDisabled,
88-
["is-hover"]: isHovered,
89-
["is-focus-visible"]: isFocused,
90-
["is-active"]: isActive,
91-
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
92-
})}
94+
[rootClass]: true,
95+
[`${rootClass}--size${size?.toUpperCase()}`]:
96+
typeof size !== "undefined",
97+
[`${rootClass}--quiet`]: isQuiet,
98+
[`${rootClass}--emphasized`]: isEmphasized,
99+
[`${rootClass}--static${capitalize(staticColor)}`]:
100+
typeof staticColor !== "undefined",
101+
["is-disabled"]: isDisabled,
102+
["is-hover"]: isHovered,
103+
["is-focus-visible"]: isFocused,
104+
["is-active"]: isActive,
105+
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
106+
})}
93107
id=${id}
94108
data-testid=${testId ?? id}
95109
popovertarget=${ifDefined(hasPopup && hasPopup !== "false" ? popupId : undefined)}
96110
role=${ifDefined(role)}
97111
style=${styleMap(customStyles)}
98112
?disabled=${isDisabled}
99-
@click=${onclick ?? function() {
100-
updateArgs({
101-
isSelected: !isSelected
102-
});
113+
@click=${function () {
114+
if (isDisabled) return;
115+
if (typeof onclick === "function") onclick();
116+
else {
117+
updateArgs({
118+
isSelected: !isSelected,
119+
isOpen: !isOpen,
120+
});
121+
}
103122
}}
104-
@focusin=${function() {
123+
@focusin=${function () {
105124
updateArgs({ isFocused: true });
106125
}}
107126
@focusout=${function() {

components/actionmenu/stories/actionmenu.stories.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ export default {
7575
tags: ["migrated"],
7676
};
7777

78-
/**
79-
* Action menu allows users to access and execute various commands or tasks related to their current workflow. It's typically triggered from an action button by user interaction.
80-
*
81-
* Note that the accessibility roles are different for an action menu compared to a normal menu. The action menu is a combination of a menu, popover, and action button.
82-
*/
8378
export const Default = ActionMenuGroup.bind({});
8479
Default.args = {
8580
triggerArgs: {
@@ -130,6 +125,8 @@ Default.args = {
130125
* By default, the menu is opened by pressing the trigger element or activating it via the <kbd>Space</kbd> or <kbd>Enter</kbd> keys. However, there may be cases where the trigger should perform a separate action on press such as selection, and should only display the menu when long pressed. For this use-case, the menu will only be opened when pressing and holding the trigger or by using the <kbd>Option</kbd> (Alt on Windows) + <kbd>Down arrow</kbd>/<kbd>Up arrow</kbd> keys while focusing the trigger.
131126
*
132127
* This example illustrates the expected visuals and states of the action menu for a trigger with both long press and short press behaviors.
128+
*
129+
* Please note that the long press functionality is not implemented in this documentation and the example serves only as a visual reference.
133130
*/
134131
export const LongPress = Template.bind({});
135132
LongPress.args = {
@@ -165,7 +162,7 @@ LongPress.parameters = {
165162
};
166163

167164
/**
168-
* Action menus can be positioned in four locals relative to the trigger but <u>only one menu can be triggered at a single time</u>.
165+
* Action menus can be positioned in four locals relative to the trigger but <em>only one menu can be triggered at a single time</em>.
169166
*/
170167
export const PlacementOptions = (args, context) => ArgGrid({
171168
Template,

components/actionmenu/stories/template.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { Template as Menu } from "@spectrum-css/menu/stories/template.js";
33
import { Template as Popover } from "@spectrum-css/popover/stories/template.js";
44
import { getRandomId } from "@spectrum-css/preview/decorators";
55

6+
import "../index.css";
7+
68
export const Template = (
79
{
810
rootClass = "spectrum-ActionMenu",
@@ -24,6 +26,15 @@ export const Template = (
2426
) => {
2527
const { updateArgs } = context;
2628

29+
document.body.addEventListener("click", function (evt) {
30+
if (evt.target.closest(`.${rootClass}`)) {
31+
return;
32+
}
33+
updateArgs({
34+
isOpen: false,
35+
});
36+
});
37+
2738
return Popover(
2839
{
2940
...popoverArgs,
@@ -40,12 +51,12 @@ export const Template = (
4051
hasPopup: "menu",
4152
hasLongPress,
4253
id: triggerId,
54+
isOpen,
55+
isSelected: isOpen,
4356
customClasses: [`${rootClass}-trigger`],
44-
onclick: hasLongPress
45-
? undefined
46-
: () => {
47-
updateArgs({ isOpen: !isOpen });
48-
},
57+
onclick: () => {
58+
updateArgs({ isOpen: !isOpen });
59+
},
4960
},
5061
context,
5162
),

components/coachmark/stories/template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const CoachContainer = (
5252
<div class="spectrum-CoachMark-header" style=${styleMap({
5353
"--mod-popover-width": "0px",
5454
"--mod-popover-height": "0px",
55-
"--mod-popover-wrapper-spacing": "0px",
55+
"--spectrum-popover-animation-distance": "0px",
5656
})}>
5757
<div class="spectrum-CoachMark-title">${title}</div>
5858
${when(

components/popover/stories/template.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const Template = ({
2121
if (isOpen) {
2222
if (["top", "bottom"].some((e) => position.startsWith(e))) {
2323
customWrapperStyles["min-inline-size"] = "var(--spectrum-popover-width)";
24-
customWrapperStyles["min-block-size"] = "calc(var(--spectrum-popover-height) + var(--spectrum-popover-trigger-height, 0px) + var(--mod-popover-wrapper-spacing, var(--spectrum-spacing-100) * 2))";
24+
customWrapperStyles["min-block-size"] = "calc(var(--spectrum-popover-height) + var(--spectrum-popover-trigger-height, 0px) + var(--spectrum-popover-animation-distance, var(--spectrum-spacing-100) * 2))";
2525
}
2626
else {
2727
customWrapperStyles["min-inline-size"] = "calc(var(--spectrum-popover-width) + var(--spectrum-popover-trigger-width, 0px))";
@@ -95,10 +95,10 @@ export const Popover = ({
9595
if (trigger) {
9696
// Translate the popover to the correct position, keeping the default spacing between the trigger and the popover in mind.
9797
if (position.startsWith("top")) {
98-
popoverAlignment["transform"] = "translateY(calc(var(--spectrum-popover-trigger-height, 0px) * -1 - var(--spectrum-spacing-100)))";
98+
popoverAlignment["transform"] = "translateY(calc(var(--spectrum-popover-trigger-height, 0px) * -1 - var(--spectrum-popover-animation-distance, var(--spectrum-spacing-100))))";
9999
}
100100
else if (position.startsWith("bottom")) {
101-
popoverAlignment["transform"] = "translateY(calc(var(--spectrum-popover-trigger-height, 0px) + var(--spectrum-spacing-100)))";
101+
popoverAlignment["transform"] = "translateY(calc(var(--spectrum-popover-trigger-height, 0px) + var(--spectrum-popover-animation-distance, var(--spectrum-spacing-100))))";
102102
}
103103

104104
// Position the popover to the correct position at the correct side of the trigger.

0 commit comments

Comments
 (0)