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

[Tabs] Fix keyboard navigation involving disabled Tabs #1449

Merged
merged 11 commits into from
Feb 24, 2025

Conversation

mj12albert
Copy link
Member

@mj12albert mj12albert commented Feb 17, 2025

Fixes #1442

Before: https://codesandbox.io/p/sandbox/tender-bassi-w74kv9

After: https://codesandbox.io/p/devbox/restless-framework-g3j43t?file=%2Fsrc%2FApp.tsx

Tabs are intentionally focusable when disabled, so it should be possible to move focus to disabled Tabs using the arrow keys. The disabled state should only disable tab activation.

@mj12albert mj12albert added component: tabs This is the name of the generic UI component, not the React module! bug 🐛 Something doesn't work labels Feb 17, 2025
Copy link

netlify bot commented Feb 17, 2025

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit ee90169
🔍 Latest deploy log https://app.netlify.com/sites/base-ui/deploys/67bc44e42729f00008b96624
😎 Deploy Preview https://deploy-preview-1449--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 site configuration.

@mj12albert mj12albert force-pushed the fix/disabled-tab-nav branch 3 times, most recently from bd7dfb7 to 7dbdef8 Compare February 17, 2025 08:22
@mj12albert

This comment was marked as outdated.

Copy link
Member

@michaldudak michaldudak left a comment

Choose a reason for hiding this comment

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

👍 I haven't found any issues in behavior.

@@ -94,6 +94,7 @@ const TabsList = React.forwardRef(function TabsList(
onHighlightedIndexChange={setHighlightedTabIndex}
onMapChange={setTabMap}
render={renderElement()}
disabledIndices={[]}
Copy link
Member

Choose a reason for hiding this comment

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

Do not recreate the array on each render.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed!

@@ -58,11 +58,15 @@ function useTabsTab(parameters: useTabsTab.Parameters): useTabsTab.ReturnValue {
return valueParam === selectedTabValue;
}, [index, selectedTabValue, valueParam]);

// when activateOnFocus is `true`, ensure the active item in Composite's roving
// focus group matches the selected Tab
const selectedValueSyncedWithHighlightedTabIndexRef = React.useRef(false);
Copy link
Member

Choose a reason for hiding this comment

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

It's a mouthful :)
But too long is much better than too short, so let's leave it.

Copy link
Member Author

Choose a reason for hiding this comment

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

this is all within a few lines so I shortened it by 12 chars 😅
isSelectionSyncedWithHighlightRef

@mj12albert mj12albert merged commit 05e3fd9 into mui:master Feb 24, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: tabs This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Tabs] Arrow keys cannot navigate to disabled Tabs
2 participants