From dd6b5ddf3a1f010909dc6388c1f715cb75ba0354 Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Mon, 17 Aug 2026 10:00:15 -0700 Subject: [PATCH] fix: preserve menu item actions in admin dropdowns. Closes #4453. --- src/components/input/MenuButton.test.tsx | 31 ++++++++++++++++++++++++ src/components/input/MenuButton.tsx | 5 +++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/components/input/MenuButton.test.tsx diff --git a/src/components/input/MenuButton.test.tsx b/src/components/input/MenuButton.test.tsx new file mode 100644 index 000000000..342490f46 --- /dev/null +++ b/src/components/input/MenuButton.test.tsx @@ -0,0 +1,31 @@ +import { Icon, MenuItem, Row, Text } from '@umami/react-zen'; +import { expect, test, vi } from 'vitest'; +import { Edit } from '@/components/icons'; +import { render, screen } from '@/test/render'; +import { MenuButton } from './MenuButton'; + +test('preserves child menu item actions while still notifying the parent handler', async () => { + const onChildAction = vi.fn(); + const onMenuAction = vi.fn(); + const { user } = render( + + + + + + + Edit + + + , + ); + + const button = screen.getByRole('button'); + + button.focus(); + await user.keyboard('{Enter}'); + await user.click(screen.getByRole('menuitem', { name: 'Edit' })); + + expect(onChildAction).toHaveBeenCalledWith('edit'); + expect(onMenuAction).toHaveBeenCalledWith('edit'); +}); diff --git a/src/components/input/MenuButton.tsx b/src/components/input/MenuButton.tsx index e99e7dfb9..ec2efa1b1 100644 --- a/src/components/input/MenuButton.tsx +++ b/src/components/input/MenuButton.tsx @@ -34,7 +34,10 @@ export function MenuButton({ {Children.map(children, child => isValidElement(child) ? cloneElement(child as ReactElement<{ onAction?: (key: Key) => void }>, { - onAction: handleAction, + onAction: (key: Key) => { + child.props.onAction?.(key); + handleAction(key); + }, }) : child, )}