-
Notifications
You must be signed in to change notification settings - Fork 70
feat(eds-core-react): call onChange with provided value if present #3893
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
feat(eds-core-react): call onChange with provided value if present #3893
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the Tabs component's onChange callback to receive the tab's value prop when available, instead of always receiving the tab's index. This change makes tab management more semantic by allowing developers to work with meaningful values rather than relying on index-based lookups.
Key Changes
- Modified
onChangecallback signature to acceptnumber | stringinstead of justnumber - Updated tab click handler to pass the tab's value when available, falling back to index
- Added comprehensive test coverage for the new behavior
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
packages/eds-core-react/src/components/Tabs/Tabs.tsx |
Updated onChange prop type signature to accept number | string |
packages/eds-core-react/src/components/Tabs/Tabs.context.ts |
Updated context handleChange type to match new signature |
packages/eds-core-react/src/components/Tabs/TabList.tsx |
Modified click handler to pass tab value when available, otherwise index |
packages/eds-core-react/src/components/Tabs/Tabs.test.tsx |
Added test to verify onChange receives value or index appropriately |
| onClick: () => handleChange($index), | ||
| onClick: () => | ||
| handleChange( | ||
| controlledActive !== undefined ? controlledActive : $index, |
Copilot
AI
Aug 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic uses controlledActive which represents the currently active tab, not the clicked tab's value. This will always pass the current active tab instead of the clicked tab's value. Should use the individual tab's value prop or $index for the clicked tab.
| controlledActive !== undefined ? controlledActive : $index, | |
| childProps.value !== undefined ? childProps.value : $index, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming of controlledActive could be confusing. I believe controlledActive represent the individual tab's value and not the current active tab. Do you agree @FredrikMWold ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, i agree that controlledActive sounds like the currently active tab and not the value of the clicked tab.
The most straight forward name would be value or tabValue
Or to rename childProps to tabProps and just use tabProps.value
…instead of always its index, with index used as a fallback
f8e5449 to
fdd17e4
Compare
|
I was wondering if it’s a common practice to have a |
|
https://www.radix-ui.com/primitives/docs/components/tabs Its not uncommen that tabs have a |
|
Great. Thank you for the examples, @FredrikMWold. I think this is a great enhancement to the component. I would prefer one solution to control the active tab, but it is also nice to not break existing solutions ⚖️ Maybe we can simplify another day ✨ |
torleifhalseth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 Thanks for the contribution @FredrikMWold!
| activeTab?: number | string | ||
| /** The callback function for selecting a tab */ | ||
| onChange?: (index: number) => void | ||
| onChange?: (value: number | string) => void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a breaking API change. Would be great if this was marked as such in the release note.
…instead of always its index, with index used as a fallback (#3893)
Before:
The
onChangefunction in theTabscomponent always received the selected tab’s index.After:
onChangenow receives the tab’svalueprop if one is provided. If novalueis set, it will fall back to the tab’s index.Why
Previously, managing tab state often meant: