Skip to content

Commit

Permalink
feat(tabs): add click handling for tab items in tests and implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
liaoyinglong committed Oct 18, 2024
1 parent 8a33eab commit 9a3550a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
23 changes: 23 additions & 0 deletions packages/components/tabs/__tests__/tabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,27 @@ describe("Tabs", () => {

expect(input).toHaveValue("23");
});

it("Tab click should be handled", async () => {
const item1Click = jest.fn();
const item2Click = jest.fn();
const wrapper = render(
<Tabs>
<Tab key="item1" data-testid="item1" title="Item 1" onClick={item1Click}>
<div>Content 1</div>
</Tab>
<Tab key="item2" data-testid="item2" title="Item 2" onClick={item2Click}>
<div>Content 2</div>
</Tab>
</Tabs>,
);
const tab1 = wrapper.getByTestId("item1");
const tab2 = wrapper.getByTestId("item2");

await user.click(tab1);
expect(item1Click).toHaveBeenCalled();

await user.click(tab2);
expect(item2Click).toHaveBeenCalled();
});
});
4 changes: 2 additions & 2 deletions packages/components/tabs/src/tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ const Tab = forwardRef<"button", TabItemProps>((props, ref) => {
rerender: true,
});

const handleClick = () => {
chain(onClick, tabProps.onClick);
const handleClick = (...args: any[]) => {
chain(onClick, tabProps.onClick)(...args);

if (!domRef?.current || !listRef?.current) return;

Expand Down

0 comments on commit 9a3550a

Please sign in to comment.