Skip to content

[tabs] Do not initially select a disabled tab - #3475

Merged
michaldudak merged 8 commits into
mui:masterfrom
michaldudak:initial-disabled-tab
Dec 10, 2025
Merged

michaldudak merged 8 commits into
mui:masterfrom
michaldudak:initial-disabled-tab

Conversation

@michaldudak

@michaldudak michaldudak commented Dec 9, 2025 •

Copy link
Copy Markdown
Member

This is a solution inspired by #2579 adapted to the current state where value is mandatory on Tab and TabPanel parts.

Due to how tabs are registered, this doesn't work with SSR - we don't know which tabs are disabled on the server. To overcome this, explicitly provide a defaultValue pointing to the first non-disabled tab.

Fixes #2098

@michaldudak
michaldudak requested a review from atomiks as a code owner December 9, 2025 11:19
@michaldudak michaldudak added the component: tabs Changes related to the tabs component. label Dec 9, 2025
@michaldudak michaldudak added the type: bug It doesn't behave as expected. label Dec 9, 2025
@pkg-pr-new

pkg-pr-new Bot commented Dec 9, 2025 •

Copy link
Copy Markdown
  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@3475
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@3475
    

commit: 3efdc42

@mui-bot

mui-bot commented Dec 9, 2025 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+396B(+0.10%) 🔺+152B(+0.12%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Dec 9, 2025

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit bb55cec
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/693805cfda45980008b10cc6
😎 Deploy Preview https://deploy-preview-3475--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Dec 9, 2025 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 3efdc42
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69396be746ef310008074d0e
😎 Deploy Preview https://deploy-preview-3475--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@michaldudak
michaldudak marked this pull request as draft December 9, 2025 11:25
@michaldudak
michaldudak marked this pull request as ready for review December 9, 2025 12:18

@LukasTy LukasTy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice work. 👍

Comment thread packages/react/src/tabs/tab/TabsTab.tsx Outdated
/**
* Whether the Tab is disabled.
*
* If a first Tab on a TabList is disabled, it won't initially be selected.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* If a first Tab on a TabList is disabled, it won't initially be selected.
* If a first Tab on a `<Tabs.List>` is disabled, it won't initially be selected.

Comment thread packages/react/src/tabs/tab/TabsTab.tsx Outdated
*
* If a first Tab on a TabList is disabled, it won't initially be selected.
* Instead, the next enabled Tab will be selected.
* However, this does not work this way during Server-Side Rendering, as it is not known

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* However, this does not work this way during Server-Side Rendering, as it is not known
* However, it does not work like this during Server-Side Rendering, as it is not known

Comment thread packages/react/src/tabs/tab/TabsTab.tsx Outdated
* Instead, the next enabled Tab will be selected.
* However, this does not work this way during Server-Side Rendering, as it is not known
* during pre-rendering which Tabs are disabled.
* To work around this, ensure that `defaultValue` or `value` on `Tabs.Root` is set to an enabled Tab's value.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* To work around this, ensure that `defaultValue` or `value` on `Tabs.Root` is set to an enabled Tab's value.
* To work around it, ensure that `defaultValue` or `value` on `<Tabs.Root>` has the value of an enabled Tab.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: tabs Changes related to the tabs component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[tabs] Disabled tabs should not be automatically picked as the initially selected tab

4 participants