Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Tabs)!: Rename onChange to onTabChange #1908

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/react/src/Tabs/Tabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ describe('Tabs', () => {
expect(screen.getByRole('tabpanel')).toHaveTextContent('Content 2')
})

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

const onChange = jest.fn()
const onTabChange = jest.fn()
render(
<Tabs onChange={onChange}>
<Tabs onTabChange={onTabChange}>
<Tabs.List>
<Tabs.Button tab={1}>Tab 1</Tabs.Button>
</Tabs.List>
Expand All @@ -106,7 +106,7 @@ describe('Tabs', () => {
const button = screen.getByRole('tab', { name: 'Tab 1' })
await user.click(button)

expect(onChange).toHaveBeenCalledWith(1)
expect(onTabChange).toHaveBeenCalledWith(1)
})

it('should be able to set the initially active tab', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export type TabsProps = {
/** The number of the active tab. Corresponds to its `tab` value. */
activeTab?: number
/* Provides the id of the activated tab. */
onChange?: (tabId: number) => void
onTabChange?: (tabId: number) => void
} & PropsWithChildren<HTMLAttributes<HTMLDivElement>>

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

const updateTab = (tab: number) => {
setActiveTabId(tab)
onChange?.(tab)
onTabChange?.(tab)
}

// Use a passed ref if it's there, otherwise use innerRef
Expand Down
2 changes: 1 addition & 1 deletion storybook/src/components/Tabs/Tabs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const meta = {
type: 'number',
},
},
onChange: {
onTabChange: {
action: 'clicked',
description: 'Provides the id of the activated tab.',
},
Expand Down