Skip to content

Commit

Permalink
fix(tabs): pass 'value' as first argument in 'onChange'
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbien committed Nov 10, 2022
1 parent 0471ccb commit 390edd8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Tabs/Tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { CommonStyledProps } from '../types';
type TabProps = {
children?: React.ReactNode;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onClick?: (event: React.MouseEvent<HTMLButtonElement>, value: any) => void;
onClick?: (value: any, event: React.MouseEvent<HTMLButtonElement>) => void;
selected?: boolean;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value?: any;
Expand Down Expand Up @@ -76,7 +76,7 @@ const Tab = forwardRef<HTMLButtonElement, TabProps>(
aria-selected={selected}
selected={selected}
onClick={(e: React.MouseEvent<HTMLButtonElement>) =>
onClick?.(e, value)
onClick?.(value, e)
}
ref={ref}
role='tab'
Expand Down
2 changes: 1 addition & 1 deletion src/Tabs/Tabs.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('<Tabs />', () => {

fireEvent.click(getAllByRole('tab')[1]);
expect(handleChange).toBeCalledTimes(1);
expect(handleChange.mock.calls[0][1]).toBe(1);
expect(handleChange.mock.calls[0][0]).toBe(1);
});
});

Expand Down
14 changes: 7 additions & 7 deletions src/Tabs/Tabs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ export function Default() {
});

const handleChange = (
_: React.MouseEvent<HTMLButtonElement>,
value: number
) => setState({ activeTab: value });
value: number,
event: React.MouseEvent<HTMLButtonElement>
) => {
console.log({ value, event });
setState({ activeTab: value });
};

const { activeTab } = state;
return (
Expand Down Expand Up @@ -88,10 +91,7 @@ export function MultiRow() {
activeTab: 'Shoes'
});

const handleChange = (
_: React.MouseEvent<HTMLButtonElement>,
value: string
) => setState({ activeTab: value });
const handleChange = (value: string) => setState({ activeTab: value });

const { activeTab } = state;
return (
Expand Down

0 comments on commit 390edd8

Please sign in to comment.