Skip to content

[scroll area] Fix focus trap with non-scrollable viewport - #4220

Merged
atomiks merged 2 commits into
mui:masterfrom
atomiks:codex/fix-scroll-area-dialog-focus-trap-4205
Mar 3, 2026
Merged

atomiks merged 2 commits into
mui:masterfrom
atomiks:codex/fix-scroll-area-dialog-focus-trap-4205

Conversation

@atomiks

@atomiks atomiks commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4205 (https://stackblitz.com/edit/tfve4lsf-gffpyxdf?file=src%2FApp.tsx)

Explanation:

ScrollArea starts with hiddenState = { x: false, y: false }, so the viewport initially renders with tabIndex=0. (fwiw this will change with #4107)

  • Old behavior: non-scrollable viewport removed tabIndex entirely. In Chromium, when that happens after focus was on the viewport, focus can fall back to <body>, which breaks dialog trap-focus flow.
  • New behavior: non-scrollable viewport gets tabIndex={-1}.
    Not in tab order. That stability keeps focus inside the dialog, so trap-focus keeps working.

@atomiks atomiks added type: bug It doesn't behave as expected. component: scroll area Changes related to the scroll area component. labels Feb 27, 2026
@pkg-pr-new

pkg-pr-new Bot commented Feb 27, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

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

commit: 01463c2

@mui-bot

mui-bot commented Feb 27, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react ▼-7B(0.00%) ▼-4B(0.00%)

Details of bundle changes


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

@netlify

netlify Bot commented Feb 27, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit de8e6a3
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69a6ccc64312e500074aca7c
😎 Deploy Preview https://deploy-preview-4220--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.

@atomiks

atomiks commented Mar 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Codex Review

Overview

This PR fixes a trap-focus edge case where a non-scrollable ScrollArea.Viewport could still participate in keyboard tab order inside a dialog. It updates viewport tab behavior and adds a focused regression test so tab navigation remains trapped within the dialog.

Findings (None)

No blocking issues found in this patch.

Confidence: 4/5

The fix is narrowly scoped to tabIndex behavior and is reinforced by a targeted dialog regression test covering the reported interaction path.

Notes

  • packages/react/src/scroll-area/viewport/ScrollAreaViewport.tsx:371 now sets tabIndex to -1 when both axes are non-scrollable and 0 otherwise.
  • packages/react/src/dialog/root/DialogRoot.test.tsx:1120 adds a regression test for Dialog.Root with modal="trap-focus" containing a non-scrollable ScrollArea.Viewport.

@atomiks
atomiks merged commit a672bbe into mui:master Mar 3, 2026
6 checks passed
@atomiks
atomiks deleted the codex/fix-scroll-area-dialog-focus-trap-4205 branch March 3, 2026 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[scroll-area] non-scrollable scroll-area breaks focus trapping of the dialog

2 participants