Skip to content

[popups] Fix page scroll jump when input has focus on unmount in Safari - #3925

Merged
atomiks merged 3 commits into
mui:masterfrom
atomiks:atomiks/fix-safari-esc-scroll
Feb 4, 2026
Merged

atomiks merged 3 commits into
mui:masterfrom
atomiks:atomiks/fix-safari-esc-scroll

Conversation

@atomiks

@atomiks atomiks commented Feb 2, 2026 •

Copy link
Copy Markdown
Contributor

Not really sure why this occurs, but:

https://deploy-preview-3925--base-ui.netlify.app/react/components/combobox#input-inside-popup

Press trigger with pointer then press Esc in Safari. Opening with a pointer then selecting an item with the keyboard also has the bug.

If you open with a keyboard instead of a pointer, it doesn't happen. Or typing and then selecting with a keyboard after opening with a pointer.

@atomiks atomiks added type: bug It doesn't behave as expected. browser: Safari Affects or fixes behavior in Apple Safari. scope: all components Widespread work has an impact on almost all components. labels Feb 2, 2026
@pkg-pr-new

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

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

  • vite-css-base-ui-example

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

commit: b3107f8

@mui-bot

mui-bot commented Feb 2, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+89B(+0.02%) 🔺+53B(+0.04%)

Details of bundle changes


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

@netlify

netlify Bot commented Feb 2, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit b3107f8
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6982fd9d2079ea000833ab6d
😎 Deploy Preview https://deploy-preview-3925--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 marked this pull request as ready for review February 2, 2026 03:07
@greptile-apps

greptile-apps Bot commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

Added a Safari-specific fix to prevent a page scroll jump bug that occurs when an input element inside a popup has focus when the popup unmounts. The fix uses useIsoLayoutEffect to detect when the popup is closing in WebKit browsers and proactively blurs any focused typeable element (input, textarea, contenteditable) before the popup unmounts.

  • Imported isWebKit from @base-ui/utils/detectBrowser and isTypeableElement from local utils
  • Added new effect that runs when open or floating changes
  • Effect checks if popup is closing (!open) in WebKit browser and blurs the active element if it's a typeable element inside the floating element
  • Uses existing utilities (activeElement, isHTMLElement, isTypeableElement, contains) to safely check conditions

Confidence Score: 5/5

  • This PR is safe to merge - it's a targeted browser-specific fix that only affects Safari/WebKit
  • The fix is well-scoped, uses existing utilities correctly, follows the codebase conventions (using useIsoLayoutEffect as required), and only activates in specific conditions (WebKit browser + popup closing + focused typeable element). The logic is sound and defensive.
  • No files require special attention

Important Files Changed

Filename Overview
packages/react/src/floating-ui-react/components/FloatingFocusManager.tsx Added Safari-specific workaround to prevent page scroll jump when focused input unmounts

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

The Esc bug is fixed

Opening with a pointer then selecting an item with the keyboard

I couldn't reproduce this though, do you mean opening with the pointer, then highlighting an item with the pointer then Enter? Also tried opening with pointer, arrow down then enter ;you mention typing after opening with pointer is fine

@atomiks

atomiks commented Feb 4, 2026

Copy link
Copy Markdown
Contributor Author

I couldn't reproduce this though, do you mean opening with the pointer, then highlighting an item with the pointer then Enter? Also tried opening with pointer, arrow down then enter ;you mention typing after opening with pointer is fine

Yeah, opening with pointer, then pressing arrow down and Enter to select an item had the issue. If you typed something in the input first (just one char) it doesn't happen

@mj12albert

Copy link
Copy Markdown
Member

Yeah, opening with pointer, then pressing arrow down and Enter to select an item

Weird, it doesn't happen to me on Sequoia + Safari 26.2 🙃

@atomiks

atomiks commented Feb 4, 2026

Copy link
Copy Markdown
Contributor Author

Weird, it doesn't happen to me on Sequoia + Safari 26.2 🙃

You need to have something selected first (doesn't happen initially), then re-open with a pointer — then it happens

@atomiks
atomiks merged commit b59d982 into mui:master Feb 4, 2026
7 checks passed
@atomiks
atomiks deleted the atomiks/fix-safari-esc-scroll branch February 4, 2026 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

browser: Safari Affects or fixes behavior in Apple Safari. scope: all components Widespread work has an impact on almost all components. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants