Skip to content

Commit

Permalink
Removed duplicate onChange (#17754)
Browse files Browse the repository at this point in the history
* fix: removed duplicate onChange

* test: added test to make sure onchange is called once

* test: fixed spelling

* fix: removed test story
  • Loading branch information
guidari authored Oct 17, 2024
1 parent a7d18f1 commit 1232b5e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
24 changes: 24 additions & 0 deletions packages/react/src/components/Menu/Menu-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,28 @@ describe('MenuItem', () => {
spy.mockRestore();
});
});

it('should call onChange once', async () => {
const onChange = jest.fn();

render(
<Menu open label="Menu">
<MenuItem label="Menu">
<MenuItemRadioGroup
label="MenuItemRadioGroup"
items={[
{ label: 'Item 1', value: '1' },
{ label: 'Item 2', value: '2' },
]}
onChange={onChange}
itemToString={(item) => item.label}
/>
</MenuItem>
</Menu>
);

await userEvent.click(screen.getByTitle('Menu'));
await userEvent.click(screen.getByTitle('Item 1'));
expect(onChange).toHaveBeenCalledTimes(1);
});
});
4 changes: 0 additions & 4 deletions packages/react/src/components/Menu/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,6 @@ export const MenuItemRadioGroup = forwardRef(function MenuItemRadioGroup<Item>(

function handleClick(item, e) {
setSelection(item);

if (onChange) {
onChange(e);
}
}

useEffect(() => {
Expand Down

0 comments on commit 1232b5e

Please sign in to comment.