Skip to content

Commit

Permalink
fix(Menu): fix menu expandType default mode the menuitem to pass onCl…
Browse files Browse the repository at this point in the history
…ick not trigger (#2502)

Co-authored-by: Heising <heising@travelconnect.cn>
  • Loading branch information
HaixingOoO and Heising authored Sep 13, 2023
1 parent b0965c3 commit 25252f7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/menu/HeadMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ const HeadMenu: FC<HeadMenuProps> = (props) => {
value={currentChildListValues.includes(value.active) ? value.active : currentChildListValues[0]}
onChange={value.onChange}
>
{childList.map(({ props }) => (
<TabPanel value={props.value} key={props.value} label={props.children}></TabPanel>
{childList.map(({ props: { children, ...restProps } }) => (
<TabPanel key={props.value} {...restProps} label={children}></TabPanel>
))}
</Tabs>
</ul>
Expand Down
18 changes: 18 additions & 0 deletions src/menu/__tests__/menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,22 @@ describe('Menu 组件测试', () => {
fireEvent.click(getByText('列表项'));
expect(ulNode.style.maxHeight).not.toBe('0');
});

test('menu 測試 menuItem onClick事件', () => {
const clickFn = vi.fn();
const { getByText } = render(
<Menu>
<SubMenu title="列表项" value="1-1">
<MenuItem value="item1" onClick={clickFn}>
仪表盘
</MenuItem>
</SubMenu>
<SubMenu title="列表项" value="2-1">
<MenuItem value="2-1-1">基础列表项</MenuItem>
</SubMenu>
</Menu>,
);
fireEvent.click(getByText('仪表盘'));
expect(clickFn).toHaveBeenCalledTimes(1);
});
});
1 change: 1 addition & 0 deletions src/tabs/TabNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ const TabNav: React.FC<TabNavProps> = (props) => {
const handleTabItemClick = (clickItem) => {
tabClick(clickItem.value);
onChange(clickItem.value);
clickItem?.onClick?.(clickItem.value);
};

const handleTabAdd = (e) => {
Expand Down

0 comments on commit 25252f7

Please sign in to comment.