Skip to content

fix(react-button): do not expose default menuIcon in useMenuButtonBase_unstable#36345

Open
mainframev wants to merge 3 commits into
microsoft:masterfrom
mainframev:fix/menu-button-base-default-icon
Open

fix(react-button): do not expose default menuIcon in useMenuButtonBase_unstable#36345
mainframev wants to merge 3 commits into
microsoft:masterfrom
mainframev:fix/menu-button-base-default-icon

Conversation

@mainframev

@mainframev mainframev commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Addresses review comment: #36320 (comment)

@mainframev mainframev requested a review from a team as a code owner June 24, 2026 16:18
@github-actions

Copy link
Copy Markdown

Pull request demo site: URL

@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-button
MenuButton
37.588 kB
9.892 kB
37.596 kB
9.902 kB
8 B
10 B
react-button
SplitButton
46.556 kB
11.533 kB
46.565 kB
11.549 kB
9 B
16 B
react-charts
AreaChart
404.498 kB
126.128 kB
404.507 kB
126.126 kB
9 B
-2 B
react-charts
DeclarativeChart
755.499 kB
220.495 kB
755.508 kB
220.508 kB
9 B
13 B
react-charts
DonutChart
314.961 kB
96.878 kB
314.97 kB
96.872 kB
9 B
-6 B
react-charts
FunnelChart
306.46 kB
93.69 kB
306.469 kB
93.695 kB
9 B
5 B
react-charts
GanttChart
387.595 kB
120.492 kB
387.603 kB
120.503 kB
8 B
11 B
react-charts
GaugeChart
314.339 kB
96.25 kB
314.348 kB
96.258 kB
9 B
8 B
react-charts
GroupedVerticalBarChart
395.467 kB
123.213 kB
395.476 kB
123.223 kB
9 B
10 B
react-charts
HeatMapChart
389.674 kB
121.531 kB
389.683 kB
121.534 kB
9 B
3 B
react-charts
HorizontalBarChart
294.633 kB
89.357 kB
294.642 kB
89.359 kB
9 B
2 B
react-charts
Legends
234.31 kB
70.189 kB
234.319 kB
70.176 kB
9 B
-13 B
react-charts
LineChart
415.826 kB
129.097 kB
415.835 kB
129.131 kB
9 B
34 B
react-charts
PolarChart
343.31 kB
106.743 kB
343.319 kB
106.738 kB
9 B
-5 B
react-charts
ScatterChart
395.209 kB
123.217 kB
395.218 kB
123.224 kB
9 B
7 B
react-charts
VerticalBarChart
431.947 kB
128.17 kB
431.956 kB
128.168 kB
9 B
-2 B
react-charts
VerticalStackedBarChart
401.671 kB
124.635 kB
401.68 kB
124.651 kB
9 B
16 B
react-components
react-components: entire library
1.296 MB
325.606 kB
1.296 MB
325.644 kB
16 B
38 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-breadcrumb
@fluentui/react-breadcrumb - package
102.926 kB
28.76 kB
react-button
Button
32.684 kB
8.504 kB
react-button
CompoundButton
39.562 kB
9.861 kB
react-button
ToggleButton
52.344 kB
10.635 kB
react-card
Card - All
93.06 kB
26.955 kB
react-card
Card
85.658 kB
25.044 kB
react-card
CardFooter
11.516 kB
4.606 kB
react-card
CardHeader
14.047 kB
5.435 kB
react-card
CardPreview
11.597 kB
4.716 kB
react-charts
HorizontalBarChartWithAxis
63 B
83 B
react-charts
SankeyChart
211.914 kB
67.836 kB
react-charts
Sparkline
80.503 kB
26.644 kB
react-components
react-components: Button, FluentProvider & webLightTheme
66.328 kB
19.02 kB
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
226.531 kB
68.074 kB
react-components
react-components: FluentProvider & webLightTheme
39.525 kB
13.113 kB
react-dialog
Dialog (including children components)
90.204 kB
27.895 kB
react-headless-components-preview
react-headless-components-preview: entire library
248.544 kB
71.466 kB
react-message-bar
MessageBar (all components)
22.306 kB
8.184 kB
react-portal-compat
PortalCompatProvider
5.567 kB
2.237 kB
react-tag-picker
@fluentui/react-tag-picker - package
174.152 kB
54.127 kB
react-teaching-popover
TeachingPopover
101.1 kB
31.859 kB
react-timepicker-compat
TimePicker
141.076 kB
46.036 kB
react-tree
FlatTree
135.901 kB
40.452 kB
react-tree
PersonaFlatTree
137.729 kB
40.967 kB
react-tree
PersonaTree
133.79 kB
39.741 kB
react-tree
Tree
131.968 kB
39.256 kB
🤖 This report was generated against 131593cb59bf73fb0024ede7afa9b635671112ab

mainframev added a commit to mainframev/fluentui that referenced this pull request Jun 24, 2026
…on_unstable

Align with the standalone react-button PR (microsoft#36345). Replaces the post-hoc
mutation of baseState.menuIcon with passing a null-safe default into
useMenuButtonBase_unstable, so menuIcon={null} still hides the icon.

This react-button change is owned by microsoft#36345 and will drop out of this
branch once microsoft#36345 merges and this branch is rebased onto master.
@@ -0,0 +1,7 @@
{

@github-actions github-actions Bot Jun 24, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵🏾‍♀️ visual changes to review in the Visual Change Report

vr-tests-react-components/Menu 1 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/Menu.Nested Submenus Small Viewport Stacked.nested menu.chromium.png 977 Changed
vr-tests-react-components/Menu Converged - submenuIndicator slotted content 1 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/Menu Converged - submenuIndicator slotted content.default.submenus open.chromium.png 413 Changed
vr-tests-react-components/Positioning 2 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/Positioning.Positioning end.chromium.png 624 Changed
vr-tests-react-components/Positioning.Positioning end.updated 2 times.chromium.png 20 Changed
vr-tests-react-components/ProgressBar converged 2 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/ProgressBar converged.Indeterminate + thickness - Dark Mode.default.chromium.png 25 Changed
vr-tests-react-components/ProgressBar converged.Indeterminate + thickness - High Contrast.default.chromium.png 155 Changed
vr-tests-react-components/TagPicker 3 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/TagPicker.disabled - Dark Mode.disabled input hover.chromium.png 658 Changed
vr-tests-react-components/TagPicker.disabled - High Contrast.disabled input hover.chromium.png 1319 Changed
vr-tests-react-components/TagPicker.disabled - RTL.disabled input hover.chromium.png 635 Changed

There were 3 duplicate changes discarded. Check the build logs for more information.

});

it('hides the menuIcon slot when menuIcon is null', () => {
const { result } = renderHook(() => useMenuButton_unstable({ menuIcon: null }, React.createRef()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we also check the edge-case if undefined overrides the default icon as well

@mainframev mainframev Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a test asserting it

defaultProps: {
children: <ChevronDownRegular />,
},
renderByDefault: true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we render it by default even if it's empty?

@mainframev mainframev Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, updated

mainframev and others added 3 commits June 25, 2026 15:23
…e_unstable

Move the default ChevronDownRegular icon out of the headless base hook
(useMenuButtonBase_unstable) and into the styled useMenuButton_unstable so
that headless consumers do not inherit a default icon. The default is applied
in a null-safe way so that menuIcon={null} still hides the icon.

Add regression tests covering menuIcon={null} on the styled hook and the
absence of a default icon on the base hook.
Align useMenuButtonBase_unstable with the renderByDefault convention used
across v9 components (useField, useMenuItemBase): render the menuIcon slot
only when a menuIcon is supplied instead of an empty span by default.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mainframev mainframev force-pushed the fix/menu-button-base-default-icon branch from 75d8fc1 to fb0e40d Compare June 25, 2026 13:24
@mainframev mainframev requested a review from dmytrokirpa June 25, 2026 13:34
expect(React.isValidElement(result.current.menuIcon?.children)).toBe(true);

const { container } = render(result.current.menuIcon?.children as React.ReactElement);
expect(container.querySelector('svg')).toBeInTheDocument();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use result.container.querySelector('svg') instead of another render?

expect(result.current.menuIcon).toBeDefined();
expect(React.isValidElement(result.current.menuIcon?.children)).toBe(true);

const { container } = render(result.current.menuIcon?.children as React.ReactElement);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants