Repository navigation
[tabs] Fix selecting tabs with function values - #5886
Merged
michaldudak merged 1 commit intoOct 6, 2026
Merged
Conversation
Tab values may be any type, but a function value was passed straight to the `useControlled` setter, which React treats as a state updater. Selecting such a tab selected whatever the function returned (and fell back to the first tab). A function `defaultValue` was likewise called as a lazy initializer. Wrap values in updaters in TabsRoot and initialize useControlled lazily. The existing 'should support values of different types' test could never fail: its assertions ran inside Promise.allSettled, which swallowed every rejection. Rewrite it as a sequential loop.
commit: |
Bundle size
PerformanceTotal duration: 509.40 ms +40.92 ms(+8.7%) | Renders: 76 (+0) | Paint: 932.43 ms +63.20 ms(+7.3%)
13 tests within noise — details Metric alarms
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
michaldudak
marked this pull request as ready for review
October 5, 2026 13:40
michaldudak
requested review from
atomiks,
colmtuite,
flaviendelangle,
jjenzz and
romgrk
as code owners
October 5, 2026 13:40
romgrk
approved these changes
Oct 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tab values can be any type (
TabsTab.Valueisany), but a tab whose value is a function can't be selected.TabsRootpasses the new value straight to theuseControlledsetter, and React treats a function passed to a state setter as an updater. Clicking a tab withvalue={() => 3}stores3, which matches no tab, so selection falls back to the first tab. A functiondefaultValuehas the same problem, becauseuseControlledpassesdefaulttoReact.useState, which calls it as a lazy initializer.The fix:
TabsRootwraps values in updaters (setValue(() => newValue)) both for user changes and for automatic fallbacks.useControlledinitializes its state lazily (useState(() => defaultProp)), so a function default is stored rather than called.Why the existing test didn't catch it
should support values of different typesalready includes() => 3, but it ran its assertions insidePromise.allSettled, which swallows every rejection, so the test could never fail. Five of its six assertions were already failing. It's now a sequential loop that also checksaria-selected.Validation
TabsRootanduseControlledsuites pass in jsdom and Chromium. ESLint and Prettier pass.Found during an audit of the test suite for tests that can't fail.