Repository navigation
[useDismiss] Bug: MacOS Safari and Firefox minimize when closing popups via ESC key - #4695
Merged
Merged
Conversation
In Safari, pressing Escape while the window is fullscreen exits fullscreen instead of closing the popup, because the handler only called stopPropagation without preventDefault. This adds preventDefault to the Escape keydown handler so the browser does not process the key after the popup has been dismissed. Made-with: Cursor
arturbien
requested review from
LukasTy,
atomiks,
colmtuite,
flaviendelangle and
michaldudak
as code owners
April 27, 2026 18:33
arturbien
marked this pull request as draft
April 27, 2026 18:34
commit: |
Bundle size
PerformanceTotal duration: 1,337.60 ms ▼-75.71 ms(-5.4%) | Renders: 53 (+0) | Paint: 2,072.63 ms ▼-98.09 ms(-4.5%)
...and 7 more. View full report Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Made-with: Cursor
arturbien
marked this pull request as ready for review
April 27, 2026 19:01
atomiks
approved these changes
Apr 27, 2026
atomiks
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the fix @arturbien
Contributor
Author
|
@atomiks thanks for lightning fast review and merge 🫡 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In MacOS Safari and Firefox, when the browser window is in fullscreen (maximized) mode, pressing Escape while a popup is open (popover, dropdown menu, select, dialog, etc.) exits the maximized/fullscreen mode which leads to a really poor UX for a very common user behavior.
BEFORE:
Screen.Recording.2026-04-27.at.20.39.08.mov
Screen.Recording.2026-04-27.at.20.57.41.mov
AFTER:
Screen.Recording.2026-04-27.at.20.39.33.mov
Screen.Recording.2026-04-27.at.20.58.19.mov
Root cause
The
closeOnEscapeKeyDownhandler inuseDismisswas callingevent.stopPropagation()but notevent.preventDefault(). WhilestopPropagationprevents other JavaScript event listeners from seeing the event, onlypreventDefaultprevents the browser's native behavior for that key. Safari's and Firefox native Escape behavior in fullscreen is to exit fullscreen, and withoutpreventDefault, that fires before (or instead of) the popup closing.Fix
Added
event.preventDefault()to the Escape keydown handler inuseDismiss, gated on!eventDetails.isCanceled— so if a consumer callscancel()in theironOpenChangecallback, the browser's default Escape behavior is preserved.Prior art
Radix UI had the exact same bug and fix:
Test plan
event.defaultPreventedistrueafter Escape dismisses a floating element.event.defaultPreventedremainsfalsewhen the consumer cancels the close viacancel().useDismisstests continue to pass.Manual verification
@atomiks lmk if there's anything misssing 🫡