-
-
Notifications
You must be signed in to change notification settings - Fork 206
fix(Dialog): prevent mask close when dragging from content to mask #543
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
Changes from all commits
da17a42
8cbf1c5
fcb258d
f4c2f1d
a808a3c
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 |
|---|---|---|
|
|
@@ -173,7 +173,10 @@ describe('dialog', () => { | |
| const { rerender } = render(<Dialog onClose={onClose} visible />); | ||
|
|
||
| // Mask close | ||
| fireEvent.click(document.querySelector('.rc-dialog-wrap')); | ||
| const mask = document.querySelector('.rc-dialog-wrap'); | ||
| fireEvent.mouseDown(mask); | ||
| fireEvent.mouseUp(mask); | ||
| fireEvent.click(mask); | ||
| jest.runAllTimers(); | ||
| expect(onClose).toHaveBeenCalled(); | ||
| onClose.mockReset(); | ||
|
|
@@ -185,6 +188,30 @@ describe('dialog', () => { | |
| expect(onClose).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should not close when dragging from content to mask', () => { | ||
| const onClose = jest.fn(); | ||
| const { getByText } = render( | ||
| <Dialog visible maskClosable onClose={onClose}> | ||
| Content | ||
| </Dialog> | ||
| ); | ||
|
|
||
| jest.runAllTimers(); | ||
|
|
||
| const content = getByText('Content'); | ||
| const mask = document.querySelector('.rc-dialog-wrap'); | ||
| if (!mask) throw new Error('Mask not found'); | ||
|
|
||
| // Simulate mouse down on content | ||
| fireEvent.mouseDown(content); | ||
| // Simulate mouse up on mask | ||
| fireEvent.mouseUp(mask); | ||
| // Simulate click on mask (since click follows mouseup) | ||
| fireEvent.click(mask); | ||
|
|
||
| expect(onClose).not.toHaveBeenCalled(); | ||
| }); | ||
|
Comment on lines
+191
to
+213
Contributor
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. The test name 'should not close when dragging from content to mask' and the associated comments are slightly misleading. The test currently simulates a |
||
|
|
||
| it('renderToBody', () => { | ||
| const container = document.createElement('div'); | ||
| document.body.appendChild(container); | ||
|
|
||
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.
To improve robustness, it's a good practice to reset
mouseDownOnMaskRef.currenttofalseafter every click attempt on the wrapper. This ensures that themousedownstate is only valid for the immediately following click, preventing unexpected behavior in complex event sequences. This also correctly handles clicks on the content that bubble up to the wrapper, resetting the state as expected.