diff --git a/packages/react/src/components/Menu/Menu-test.js b/packages/react/src/components/Menu/Menu-test.js index 83c50452aaba..c1a2d4979fa1 100644 --- a/packages/react/src/components/Menu/Menu-test.js +++ b/packages/react/src/components/Menu/Menu-test.js @@ -255,7 +255,7 @@ describe('MenuItem', () => { }); }); - it('should call onChange once', async () => { + it('should call MenuItemRadioGroup onChange once', async () => { const onChange = jest.fn(); render( @@ -278,4 +278,33 @@ describe('MenuItem', () => { await userEvent.click(screen.getByTitle('Item 1')); expect(onChange).toHaveBeenCalledTimes(1); }); + + it('should call MenuItemSelectable onChange once with correct value', async () => { + const onChange = jest.fn(); + + const { rerender } = render( +
+ ); + + await userEvent.click(screen.getByTitle('Item 1')); + expect(onChange).toHaveBeenCalledTimes(1); + expect(onChange).toHaveBeenCalledWith(true); + + onChange.mockClear(); + rerender( + + ); + + await userEvent.click(screen.getByTitle('Item 1')); + expect(onChange).toHaveBeenCalledTimes(1); + expect(onChange).toHaveBeenCalledWith(false); + }); }); diff --git a/packages/react/src/components/Menu/MenuItem.tsx b/packages/react/src/components/Menu/MenuItem.tsx index 3a07dfd6088e..b709a8f6633c 100644 --- a/packages/react/src/components/Menu/MenuItem.tsx +++ b/packages/react/src/components/Menu/MenuItem.tsx @@ -377,10 +377,6 @@ export const MenuItemSelectable = forwardRef< function handleClick(e) { setChecked(!checked); - - if (onChange) { - onChange(e); - } } useEffect(() => {