-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: Ignore presses retargeted to the document element in dismissable modals #10511
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,5 +62,38 @@ describe('useModalOverlay', function () { | |
| fireEvent.click(document.body); | ||
| expect(onOpenChange).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should not hide the overlay when a press is retargeted to the document element', function () { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move these tests up to the RAC level and demonstrate the use case you brought up? |
||
| // When the pressed element is removed from the DOM mid-press (e.g. a button swapped | ||
| // out after an async mutation), the browser retargets the press events to the | ||
| // document element. That must not be treated as a press outside the modal. | ||
| let onOpenChange = jest.fn(); | ||
| render( | ||
| <Example | ||
| isOpen | ||
| onOpenChange={onOpenChange} | ||
| isDismissable /> | ||
| ); | ||
| pressStart(document.documentElement); | ||
| pressEnd(document.documentElement); | ||
| fireEvent.click(document.documentElement); | ||
|
Comment on lines
+77
to
+79
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how is this pressing an element that is swapped mid press? it's clicking the documentElement in every event |
||
| expect(onOpenChange).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should ignore a retargeted press even if shouldCloseOnInteractOutside returns true', function () { | ||
| let onOpenChange = jest.fn(); | ||
| render( | ||
| <Example | ||
| isOpen | ||
| onOpenChange={onOpenChange} | ||
| isDismissable | ||
| shouldCloseOnInteractOutside={() => true} | ||
| /> | ||
| ); | ||
| pressStart(document.documentElement); | ||
| pressEnd(document.documentElement); | ||
| fireEvent.click(document.documentElement); | ||
| expect(onOpenChange).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happened to the
isConnectedcheck you proposed?