Skip to content

[tabs] Generalize disabled item handling in composite system and fix tab selection - #2579

Closed
mnajdova with Copilot wants to merge 40 commits into
masterfrom
copilot/fix-21c53aee-9b31-4c86-a27d-e9d338ae5c3c
Closed

mnajdova with Copilot wants to merge 40 commits into
masterfrom
copilot/fix-21c53aee-9b31-4c86-a27d-e9d338ae5c3c

Conversation

Copilot AI commented Aug 25, 2025 •

Copy link
Copy Markdown
Contributor

Fixes #2098 by enhancing the composite system to automatically skip disabled items and improving tab selection behavior.

Previously, when no explicit value or defaultValue was provided to Tabs.Root, the component would always select the first tab (index 0) by default, even if that tab was disabled. Additionally, the composite system used by tabs and other components would default to highlighting the first item (index 0) for keyboard navigation, even if disabled.

// Before: First tab gets selected and highlighted even though it's disabled
<Tabs.Root>
  <Tabs.List>
    <Tabs.Tab disabled>Tab 1 (Disabled)</Tabs.Tab>
    <Tabs.Tab>Tab 2</Tabs.Tab>
    <Tabs.Tab>Tab 3</Tabs.Tab>
  </Tabs.List>
  {/* Tab 1 would be selected despite being disabled */}
</Tabs.Root>

The fix introduces a generalized approach that benefits all composite-based components, but only if they set a new flag available: ignoreDisabledItemsOnInitialHiglighting, so that we don't break previous behavior that makes sense for components like menus for example:

Experiment link: https://deploy-preview-2579--base-ui.netlify.app/experiments/disabled-tabs

@mui-bot

mui-bot commented Aug 25, 2025 •

Copy link
Copy Markdown

Bundle size report

Total Size Change: 🔺+1.08KB(+0.08%) - Total Gzip Change: 🔺+502B(+0.10%)
Files: 69 total (0 added, 0 removed, 7 changed)

Show details for 69 more bundles

@base-ui-components/react/tabs parsed: 🔺+338B(+1.29%) gzip: 🔺+138B(+1.47%)
@base-ui-components/react parsed: 🔺+337B(+0.11%) gzip: 🔺+164B(+0.17%)
@base-ui-components/react/menubar parsed: 🔺+81B(+0.37%) gzip: 🔺+38B(+0.48%)
@base-ui-components/react/navigation-menu parsed: 🔺+81B(+0.09%) gzip: 🔺+54B(+0.17%)
@base-ui-components/react/radio-group parsed: 🔺+81B(+0.38%) gzip: 🔺+34B(+0.42%)
@base-ui-components/react/toggle-group parsed: 🔺+81B(+0.54%) gzip: 🔺+39B(+0.69%)
@base-ui-components/react/toolbar parsed: 🔺+81B(+0.41%) gzip: 🔺+35B(+0.50%)
@base-ui-components/react/accordion parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/alert-dialog parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/avatar parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/checkbox parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/checkbox-group parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/collapsible parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/context-menu parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/dialog parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/direction-provider parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/field parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/fieldset parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/form parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/input parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/menu parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/merge-props parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/meter parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/number-field parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/popover parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/preview-card parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/progress parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/radio parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/scroll-area parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/select parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/separator parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/slider parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/switch parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/toast parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/toggle parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/tooltip parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/types parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/unstable-no-ssr parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/unstable-use-media-query parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/use-render parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/detectBrowser parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/error parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/fastObjectShallowCompare parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/generateId parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/getReactElementRef parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/inertValue parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/isElementDisabled parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/isMouseWithinBounds parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/mergeObjects parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/owner parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/reactVersion parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/safeReact parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/store parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useAnimationFrame parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useControlled parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useEnhancedClickHandler parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useEventCallback parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useForcedRerendering parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useId parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useInterval parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useIsoLayoutEffect parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useLatestRef parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useMergedRefs parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useOnFirstRender parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useOnMount parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useRefWithInit parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useTimeout parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/visuallyHidden parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/warn parsed: 0B(0.00%) gzip: 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against a1ad09e

@netlify

netlify Bot commented Aug 25, 2025 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 34944b9
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6932d50134eefc0008e822dc
😎 Deploy Preview https://deploy-preview-2579--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.

Copilot AI changed the title [WIP] Fix @mui/base-ui/issues/2098 by setting the default tab to the first non-disabled panel. If all tabs are disabled show a warning [tabs] Fix default tab selection to skip disabled tabs Aug 25, 2025
Copilot AI requested a review from mnajdova August 25, 2025 07:46
@atomiks

atomiks commented Aug 25, 2025

Copy link
Copy Markdown
Contributor

@copilot check if this can be generalized inside useCompositeRoot's onMapChange handler instead of an effect specific to tabs. The handler only checks for ACTIVE_COMPOSITE_ITEM to set the initial highlighted index different from 0, but it could also check for disabled items as well to skip them initially

Copilot AI commented Aug 25, 2025

Copy link
Copy Markdown
Contributor Author

@copilot check if this can be generalized inside useCompositeRoot's onMapChange handler instead of an effect specific to tabs. The handler only checks for ACTIVE_COMPOSITE_ITEM to set the initia...

I've generalized this logic in useCompositeRoot's onMapChange handler as suggested. The enhancement now:

  1. Enhanced useCompositeRoot.onMapChange: When no ACTIVE_COMPOSITE_ITEM is found, it now uses findNonDisabledListIndex to find the first non-disabled item instead of defaulting to index 0
  2. Updated TabsList: Now properly tracks disabledIndices from tab metadata (similar to ToolbarRoot) and passes it to CompositeRoot
  3. Benefits all composite components: This improvement automatically applies to any component using the composite system

The tabs-specific value selection logic remains in TabsRoot since it handles actual tab selection (different from keyboard navigation highlighting), but now both systems work together seamlessly.

Commit: 972495f

Copilot AI changed the title [tabs] Fix default tab selection to skip disabled tabs [tabs] Generalize disabled item handling in composite system and fix tab selection Aug 25, 2025
Copilot AI requested a review from atomiks August 25, 2025 08:05
@pkg-pr-new

pkg-pr-new Bot commented Aug 26, 2025 •

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

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

commit: 34944b9

@mnajdova
mnajdova marked this pull request as ready for review September 3, 2025 13:28

@mnajdova mnajdova 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.

I'm approving, but also I did most of the changes, so would be great to have at least another review 😄

@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.

Wording nitpick. 🙈

@atomiks

atomiks commented Sep 5, 2025

Copy link
Copy Markdown
Contributor

Not sure if related but in the experiment the panel isn't visible during server pre-rendering, only appearing after hydration

@mnajdova

Copy link
Copy Markdown
Member

Not sure if related but in the experiment the panel isn't visible during server pre-rendering, only appearing after hydration

Yeah, I just noticed the same, from what I understand it's because we are depending on the tab map to be available for the detection of the disabled state, we will likely need to change the logic in order to fix this, so we depend on props only, and not on the underlaying elements. I may be missing something though.

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Sep 11, 2025
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 3, 2025
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 8, 2025
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 22, 2025
@mnajdova mnajdova assigned michaldudak and unassigned mnajdova Oct 23, 2025
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 29, 2025
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Dec 5, 2025
@michaldudak

Copy link
Copy Markdown
Member

Implemented in #3475

@oliviertassinari
oliviertassinari deleted the copilot/fix-21c53aee-9b31-4c86-a27d-e9d338ae5c3c branch May 2, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accessibility a11y 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

7 participants