Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix: menu component hardening — icon sizing, item density, section headings (#946)

Cindy Zhang280e173274eb
diff --git a/apps/storybook/stories/MoreMenu.stories.tsx b/apps/storybook/stories/MoreMenu.stories.tsx
index 6106bc246b..30e0a35533 100644
--- a/apps/storybook/stories/MoreMenu.stories.tsx
+++ b/apps/storybook/stories/MoreMenu.stories.tsx
@@ -8,6 +8,7 @@ import {
DocumentDuplicateIcon,
ArrowDownTrayIcon,
ShareIcon,
+ Cog6ToothIcon,
} from '@heroicons/react/24/outline';
const meta: Meta<typeof XDSMoreMenu> = {
@@ -290,3 +291,31 @@ export const WithDisabledItems: Story = {
/>
),
};
+
+// Custom trigger icon — replaces the default three-dots
+export const CustomIcon: Story = {
+ render: () => (
+ <div style={{display: 'flex', gap: 16, alignItems: 'center'}}>
+ <XDSMoreMenu
+ icon={<Cog6ToothIcon />}
+ label="Settings"
+ items={[
+ {label: 'Preferences', onClick: () => console.log('Preferences')},
+ {label: 'Account', onClick: () => console.log('Account')},
+ {label: 'Logout', onClick: () => console.log('Logout')},
+ ]}
+ />
+ <XDSMoreMenu
+ icon={<PencilIcon />}
+ label="Edit options"
+ items={[
+ {label: 'Edit title', onClick: () => console.log('Edit title')},
+ {
+ label: 'Edit description',
+ onClick: () => console.log('Edit description'),
+ },
+ ]}
+ />
+ </div>
+ ),
+};
diff --git a/packages/core/src/Button/XDSButton.tsx b/packages/core/src/Button/XDSButton.tsx
index 18fafdbde0..d33d34ef3e 100644
--- a/packages/core/src/Button/XDSButton.tsx
+++ b/packages/core/src/Button/XDSButton.tsx
@@ -99,6 +99,12 @@ const styles = stylex.create({
alignItems: 'center',
color: 'inherit',
},
+ iconWrapper: {
+ display: 'inline-flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ flexShrink: 0,
+ },
contentWrapper: {
display: 'contents',
},
@@ -135,6 +141,16 @@ const sizeStyles = stylex.create({
},
});
+/**
+ * Icon size per button size.
+ * Matches XDSIcon sizing: sm/md=16px, lg=20px.
+ */
+const iconSizeStyles = stylex.create({
+ sm: {width: 16, height: 16, fontSize: 16},
+ md: {width: 16, height: 16, fontSize: 16},
+ lg: {width: 20, height: 20, fontSize: 20},
+});
+
/**
* Variant styles using backgroundImage for layered colors
* Pseudo-classes are nested within properties per StyleX recommendation
@@ -523,7 +539,12 @@ export function XDSButton({
<span
{...stylex.props(styles.contentWrapper)}
aria-hidden={isLoadingState || undefined}>
- {icon}
+ {icon && (
+ <span
+ {...stylex.props(styles.iconWrapper, iconSizeStyles[size])}>
+ {icon}
+ </span>
+ )}
{isIconOnly ? null : (
<span {...stylex.props(styles.labelText)}>{children ?? label}</span>
)}
diff --git a/packages/core/src/DropdownMenu/XDSDropdownMenu.tsx b/packages/core/src/DropdownMenu/XDSDropdownMenu.tsx
index 669ab69054..ab5c51c80e 100644
--- a/packages/core/src/DropdownMenu/XDSDropdownMenu.tsx
+++ b/packages/core/src/DropdownMenu/XDSDropdownMenu.tsx
@@ -41,6 +41,24 @@ import {
} from '../theme/tokens.stylex';
import {xdsClassName, mergeProps} from '../utils';
+/**
+ * Size-aware item padding.
+ * sm triggers → tighter vertical padding (4px block, 8px inline)
+ * md/lg triggers → standard padding (8px all around, inherited from base item style)
+ */
+const itemSizeStyles = stylex.create({
+ sm: {
+ paddingBlock: spacingVars['--spacing-1'],
+ paddingInline: spacingVars['--spacing-2'],
+ },
+ md: {
+ // Uses base item padding (--spacing-2 all around)
+ },
+ lg: {
+ // Uses base item padding (--spacing-2 all around)
+ },
+});
+
const styles = stylex.create({
// Dropdown container
dropdown: {
@@ -75,9 +93,15 @@ const styles = stylex.create({
minWidth: typeof width === 'number' ? `${width}px` : width,
}),
- // Section divider with label
- sectionDivider: {
- marginBlock: spacingVars['--spacing-1'],
+ // Section heading label (replaces divider for named sections)
+ sectionHeading: {
+ paddingBlock: spacingVars['--spacing-1'],
+ paddingInline: spacingVars['--spacing-2'],
+ fontFamily: typographyVars['--font-family-body'],
+ fontSize: typeScaleVars['--text-supporting-size'],
+ lineHeight: typeScaleVars['--text-supporting-leading'],
+ color: colorVars['--color-text-secondary'],
+ userSelect: 'none',
},
// Divider
@@ -322,6 +346,9 @@ export function XDSDropdownMenu({
}: XDSDropdownMenuProps) {
const menuId = useId();
+ // Derive menu item density from button size
+ const menuSize = button?.size ?? 'md';
+
const buttonRef = useRef<HTMLButtonElement>(null);
// Internal state for uncontrolled mode
@@ -512,6 +539,7 @@ export function XDSDropdownMenu({
onMouseEnter={() => handleItemMouseEnter(item, flatIndex)}
{...stylex.props(
styles.item,
+ itemSizeStyles[menuSize],
isHighlighted && styles.itemHighlighted,
item.isDisabled && styles.itemDisabled,
)}>
@@ -521,6 +549,7 @@ export function XDSDropdownMenu({
},
[
children,
+ menuSize,
highlightedIndex,
getItemId,
handleItemClick,
@@ -546,17 +575,16 @@ export function XDSDropdownMenu({
sectionItems.push(renderItem(item, flatIndex));
flatIndex++;
}
- if (option.title) {
- elements.push(
- <XDSDivider
- key={`section-divider-${i}`}
- label={option.title}
- xstyle={styles.sectionDivider}
- />,
- );
- }
elements.push(
<div key={`section-${i}`} role="group" aria-label={option.title}>
+ {option.title && (
+ <div
+ key={`section-heading-${i}`}
+ {...stylex.props(styles.sectionHeading)}
+ aria-hidden="true">
+ {option.title}
+ </div>
+ )}
{sectionItems}
</div>,
);
diff --git a/packages/core/src/MoreMenu/XDSMoreMenu.tsx b/packages/core/src/MoreMenu/XDSMoreMenu.tsx
index 074e1b7181..09b8301c77 100644
--- a/packages/core/src/MoreMenu/XDSMoreMenu.tsx
+++ b/packages/core/src/MoreMenu/XDSMoreMenu.tsx
@@ -52,6 +52,24 @@ import {xdsClassName, mergeProps} from '../utils';
// Styles
// =============================================================================
+/**
+ * Size-aware item padding.
+ * sm triggers → tighter vertical padding (4px block, 8px inline)
+ * md/lg triggers → standard padding (8px all around, inherited from base item style)
+ */
+const itemSizeStyles = stylex.create({
+ sm: {
+ paddingBlock: spacingVars['--spacing-1'],
+ paddingInline: spacingVars['--spacing-2'],
+ },
+ md: {
+ // Uses base item padding (--spacing-2 all around)
+ },
+ lg: {
+ // Uses base item padding (--spacing-2 all around)
+ },
+});
+
const styles = stylex.create({
dropdown: {
boxSizing: 'border-box',
@@ -73,8 +91,14 @@ const styles = stylex.create({
marginBlockStart: spacingVars['--spacing-1'],
marginBlockEnd: spacingVars['--spacing-1'],
},
- sectionDivider: {
- marginBlock: spacingVars['--spacing-1'],
+ sectionHeading: {
+ paddingBlock: spacingVars['--spacing-1'],
+ paddingInline: spacingVars['--spacing-2'],
+ fontFamily: typographyVars['--font-family-body'],
+ fontSize: typeScaleVars['--text-supporting-size'],
+ lineHeight: typeScaleVars['--text-supporting-leading'],
+ color: colorVars['--color-text-secondary'],
+ userSelect: 'none',
},
divider: {
marginBlock: spacingVars['--spacing-1'],
@@ -394,6 +418,7 @@ export function XDSMoreMenu({
onMouseEnter={() => handleItemMouseEnter(item, flatIndex)}
{...stylex.props(
styles.item,
+ itemSizeStyles[size],
isHighlighted && styles.itemHighlighted,
item.isDisabled && styles.itemDisabled,
)}>
@@ -403,6 +428,7 @@ export function XDSMoreMenu({
},
[
children,
+ size,
highlightedIndex,
getItemId,
handleItemClick,
@@ -427,17 +453,16 @@ export function XDSMoreMenu({
sectionItems.push(renderItem(item, flatIndex));
flatIndex++;
}
- if (option.title) {
- elements.push(
- <XDSDivider
- key={`section-divider-${i}`}
- label={option.title}
- xstyle={styles.sectionDivider}
- />,
- );
- }
elements.push(
<div key={`section-${i}`} role="group" aria-label={option.title}>
+ {option.title && (
+ <div
+ key={`section-heading-${i}`}
+ {...stylex.props(styles.sectionHeading)}
+ aria-hidden="true">
+ {option.title}
+ </div>
+ )}
{sectionItems}
</div>,
);