Skip to content
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

[fixed]:1015 - Fixed closing by click on layout #1018

Conversation

ErikDeviashin
Copy link

Fixes #1015

Changes proposed:

  • Fix incorrect behavior when you need to click twice on the overlay to close modal window if you click on something with event.stopPropagation() inside content block and add a test case for that.
  • Fix test cases for the overlay MD -> content MU && content MD -> overlay MU cases because they don't work correctly without the "click" itself.

Upgrade Path (for changed or removed APIs): -

Acceptance Checklist:

  • The commit message follows the guidelines in CONTRIBUTING.md.
  • Documentation (README.md) and examples have been updated as needed.
  • If this is a code change, a spec testing the functionality has been added.
  • If the commit message has [changed] or [removed], there is an upgrade path above.

- Fixed incorrect behavior when you need to click twice on the overlay to close modal window if you click on something with event.stopPropagation() inside content block.
- Wrote a test case for closing modal by click on the overlay after click on something placed  inside modal and containing stopPropagation for the "click" event. Fixed test cases for the overlay MD -> content MU && content MD -> overlay MU cases.
@@ -222,6 +222,7 @@ export default () => {
withModal(props, null, modal => {
mouseDownAt(moverlay(modal));
mouseUpAt(mcontent(modal));
clickAt(mcontent(modal));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, mouse down and click at has the effect of a double click.

@@ -236,9 +237,40 @@ export default () => {
withModal(props, null, modal => {
mouseDownAt(mcontent(modal));
mouseUpAt(moverlay(modal));
clickAt(moverlay(modal));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Author

@ErikDeviashin ErikDeviashin Apr 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this again by simply adding the log to every content and layout event. And right now only the mouseUp and mouseDown events fire, but in the code they don't have the logic to close the modal, so we have false "true" results, because of course the modal can't be closed.

Screenshot 2023-04-24 at 16 39 54

For example I created this reference. As you can see in lines 18-19, I remove content mouseUp and mouseDown events and after that in browser window we have both issues with modal closing. But if I comment out this methods in source the tests will still give "true" results.

Screenshot 2023-04-24 at 16 50 02

But if we add clickAt(moverlay(modal)) then we will have the correct results, which match the real results I got on the actual product before (and during) these tests, and than we will be able to catch these errors.

Screenshot 2023-04-24 at 17 09 58

I hope this proofs is sufficient. Let me know what you think about it.
I'll fix line 225 because I used clickAt mcontent instead of moverlay but this isn't correct as I saw during the tests.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah now I remember it...

The mouse down and up are to test the scenario where you click and hold on a content and release (mouse up) on the overlay.

Copy link
Author

@ErikDeviashin ErikDeviashin Apr 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's it!
It just didn't work when I ran the tests, so I compared it to real behavior and suggesting a way to fix the tests. Now they works at least for me :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess in the end the result is correct, but I'm not sure if the test "examplifies" the behavior.

I need to think about it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one too.

If I press down on the content, drag to the overlay, it must not close the modal.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
clickAt(moverlay(modal));

- Fixed test case for the overlay MD -> content MU.
@ErikDeviashin ErikDeviashin requested a review from diasbruno April 24, 2023 14:44
@diasbruno
Copy link
Collaborator

@ErikDeviashin Can you please rebase your PR please? Jut fixed the action issue.

@ErikDeviashin
Copy link
Author

ErikDeviashin commented Apr 29, 2023

@ErikDeviashin Can you please rebase your PR please? Jut fixed the action issue.

@diasbruno Sure, did it

@@ -222,6 +222,7 @@ export default () => {
withModal(props, null, modal => {
mouseDownAt(moverlay(modal));
mouseUpAt(mcontent(modal));
clickAt(moverlay(modal));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the behavoir I was talking about.

This clickAt shouldn't be here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
clickAt(moverlay(modal));

Comment on lines +263 to +264
mouseDownAt(innerButton);
mouseUpAt(innerButton);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mouseDownAt(innerButton);
mouseUpAt(innerButton);

Comment on lines +267 to +268
mouseDownAt(moverlay(modal));
mouseUpAt(moverlay(modal));
Copy link
Collaborator

@diasbruno diasbruno Apr 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mouseDownAt(moverlay(modal));
mouseUpAt(moverlay(modal));

@diasbruno
Copy link
Collaborator

I've made a few suggestions, I think that is what we are expecting from your new test.

@diasbruno
Copy link
Collaborator

Those 2 other tests, they need to stay the same to guarantee the behavoir when dragging from the content -> overlay and overlay -> content.

@ErikDeviashin
Copy link
Author

ErikDeviashin commented May 6, 2023

Hi, @diasbruno, sorry fore disappearing! Intense week.

I almost ready to do whatever you say, but I just want to clarify one last time:
Without handling all the mouse events, the tests will not have behavior close to real. Here, I made one more example for you, just with logs on every events for the overlay and for the content. You can drag the mouse from the content to the overlay and vice versa and you will see that the onClick event is always fired on overlay in this scenario. That's why I think we need to handle this in the tests.

I can remove all events from tests, but then the tests will gave wrong results and wouldn't catch errors that they should catch as it was in case that I described earlier.

In case of the new test will also be incorrect behavior, because the very problem of 2 clicks on overlay appears from the logic in the mouseDown event. If this event is not in the test, the test will show that behavior is correct even now without my fixes but as we know, in fact there is a problem now.

I won't push anymore, but I do think it would be better to fix the tests.

@diasbruno diasbruno closed this May 6, 2023
@diasbruno
Copy link
Collaborator

Ok. I'll have a look when I have time.
Thanks so much for taking the time to help with this issue.

@khmelevskii
Copy link
Contributor

@diasbruno it would be very cool if this fix will be merged to master. I have the same problem and I can't see any workaround to fix it

@diasbruno
Copy link
Collaborator

diasbruno commented Jun 17, 2023

@khmelevskii This patch needs a better look to see if it is right...
If you have time, you can take this patch and give it a try...

What I expect:

@khmelevskii
Copy link
Contributor

Thank you @diasbruno ! it will be pretty difficult to find time for this soon, but thank you for sharing correct expectations.

@ErikDeviashin
Copy link
Author

@diasbruno @khmelevskii
I had to change the solution in our project to just using an extra variable like
this.preventOverlayMouseDown = false (ModalPortal.js 285:42)

This is used like
this.preventOverlayMouseDown = true; (in handleContentOnMouseDown func on ModalPortal.js 236:44 line)
and
if (_this.preventOverlayMouseDown) { _this.preventOverlayMouseDown = false; } else { _this.shouldClose = null; }
(In handleOverlayOnMouseDown func on ModalPortal.js 223:7 line)

This is better just because using event.stopPropagation(); broke our tooltips a bit, so it might conflict with different libs that use the mouseDown event.

@khmelevskii If you need some quick solution look at the patch-package library because as you can see it can take a while before it gets fixed. I am using patch-package in our project to apply the changes written above

@khmelevskii
Copy link
Contributor

Thank you @diasbruno ! I will try

@see2ever
Copy link

see2ever commented Jan 4, 2024

@diasbruno @khmelevskii I had to change the solution in our project to just using an extra variable like this.preventOverlayMouseDown = false (ModalPortal.js 285:42)

This is used like this.preventOverlayMouseDown = true; (in handleContentOnMouseDown func on ModalPortal.js 236:44 line) and if (_this.preventOverlayMouseDown) { _this.preventOverlayMouseDown = false; } else { _this.shouldClose = null; } (In handleOverlayOnMouseDown func on ModalPortal.js 223:7 line)

This is better just because using event.stopPropagation(); broke our tooltips a bit, so it might conflict with different libs that use the mouseDown event.

@khmelevskii If you need some quick solution look at the patch-package library because as you can see it can take a while before it gets fixed. I am using patch-package in our project to apply the changes written above

because those line number are not match the source file, it would be more clear if the patch file pasted here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants