Skip to content

Commit 2deb358

Browse files
authored
fix(Tabs)!: Rename onChange to onTabChange (#1908)
1 parent 28bc5cc commit 2deb358

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

packages/react/src/Tabs/Tabs.test.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ describe('Tabs', () => {
9191
expect(screen.getByRole('tabpanel')).toHaveTextContent('Content 2')
9292
})
9393

94-
it('calls onChange with the newly activated tab', async () => {
94+
it('calls onTabChange with the newly activated tab', async () => {
9595
const user = userEvent.setup()
9696

97-
const onChange = jest.fn()
97+
const onTabChange = jest.fn()
9898
render(
99-
<Tabs onChange={onChange}>
99+
<Tabs onTabChange={onTabChange}>
100100
<Tabs.List>
101101
<Tabs.Button tab={1}>Tab 1</Tabs.Button>
102102
</Tabs.List>
@@ -106,7 +106,7 @@ describe('Tabs', () => {
106106
const button = screen.getByRole('tab', { name: 'Tab 1' })
107107
await user.click(button)
108108

109-
expect(onChange).toHaveBeenCalledWith(1)
109+
expect(onTabChange).toHaveBeenCalledWith(1)
110110
})
111111

112112
it('should be able to set the initially active tab', () => {

packages/react/src/Tabs/Tabs.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ export type TabsProps = {
1616
/** The number of the active tab. Corresponds to its `tab` value. */
1717
activeTab?: number
1818
/* Provides the id of the activated tab. */
19-
onChange?: (tabId: number) => void
19+
onTabChange?: (tabId: number) => void
2020
} & PropsWithChildren<HTMLAttributes<HTMLDivElement>>
2121

2222
const TabsRoot = forwardRef(
23-
({ activeTab, children, className, onChange, ...restProps }: TabsProps, ref: ForwardedRef<HTMLDivElement>) => {
23+
({ activeTab, children, className, onTabChange, ...restProps }: TabsProps, ref: ForwardedRef<HTMLDivElement>) => {
2424
const tabsId = useId()
2525
const innerRef = useRef<HTMLDivElement>(null)
2626
const [activeTabId, setActiveTabId] = useState(0)
@@ -45,7 +45,7 @@ const TabsRoot = forwardRef(
4545

4646
const updateTab = (tab: number) => {
4747
setActiveTabId(tab)
48-
onChange?.(tab)
48+
onTabChange?.(tab)
4949
}
5050

5151
// Use a passed ref if it's there, otherwise use innerRef

storybook/src/components/Tabs/Tabs.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const meta = {
7676
type: 'number',
7777
},
7878
},
79-
onChange: {
79+
onTabChange: {
8080
action: 'clicked',
8181
description: 'Provides the id of the activated tab.',
8282
},

0 commit comments

Comments
 (0)