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, )}