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

BUGFIX: Limit click-outside handling for dialogs to their semi-transparent overlay #3492

Merged
merged 6 commits into from
Jul 4, 2023

Conversation

grebaldi
Copy link
Contributor

@grebaldi grebaldi commented May 12, 2023

fixes: #2925

The problem

As documented in #2925, our click-outside-handling for dialogs is a tiny bit too aggressive, which leads to problems with stacked dialogs.

The solution

I removed the enhanceWithClickOutside decorator from the <Dialog/>-component and replaced its behavior with a simple onClick-handler that is limited to the semi-transparent overlay that surrounds every dialog.

The other issue described in #2925 (overlays do not cover entire user interface) is being addressed over here: #3491

EDIT: Some more changes were necessary to apply the same behavior to when the escape key gets pressed. A detailed description of the reasoning behind those changes can be found in this comment: #3492 (comment)

@grebaldi grebaldi linked an issue May 12, 2023 that may be closed by this pull request
@github-actions github-actions bot added Bug Label to mark the change as bugfix 7.3 labels May 12, 2023
@grebaldi grebaldi force-pushed the bugfix/2925/dialog-click-outside branch from f7918ca to bfd2024 Compare May 12, 2023 15:26
@crydotsnake crydotsnake self-requested a review June 1, 2023 13:48
Copy link
Member

@crydotsnake crydotsnake left a comment

Choose a reason for hiding this comment

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

It works great with mouse clicks! But if i press the escape (esc) key on my keyboard, it closes all overalys. Can we intercept the escape key as well?

@grebaldi
Copy link
Contributor Author

grebaldi commented Jun 5, 2023

Very good point! I'll take a look at that :)

@grebaldi
Copy link
Contributor Author

grebaldi commented Jun 6, 2023

Well, interesting: I looked at the Escape-Key handling for the dialogs and found that since 2018 react-close-on-escape was supposed to be replaced by a vanilla solution (see: #2274).

Yet, somehow react-close-on-escape managed to sneak back in. I'll try to restore the intent of #2274 within this PR, but as of yet I have no idea what happened there.

Maybe it has something to do with the large esbuild change (but that's a wild, wild guess).
EDIT: I wasn't thinking straight here... esbuild cannot be the cause, since we're on 7.3 🤦

/cc @mhsdesign @Sebobo @markusguenther

@mhsdesign
Copy link
Member

you deserve a medal for b13d470 ;)

we definitely make sure that this doesnt happen with esbuild (despite the different import syntax, but didnt think the webpack stack had any obvious flaws like this one ^^)


Some modules referred to the components via

import { /* ... */  } from '@neos-project/react-ui-components';

This caused webpack to pull the components from
'@neos-project/react-ui-components/lib-esm' rather than
'@neos-project/react-ui-components/src', leading to the
component modules being bundled twice.

The solution was to change those reference to an explicit:

import { /* ... */  } from '@neos-project/react-ui-components/src';

Now the react-ui-components are only bundled once.

@grebaldi
Copy link
Contributor Author

This was more than I thought :)

My plan was to have some global entity that can ensure a global order of stacked dialogs and close them in LIFO order when the escape-key is hit.

Plan didn't work at first try, because it turned out that webpack was bundling the react-components twice. Plugins would receive a different version of the components than the main UI - thus also a different version of the global stack-management entity.

So, I looked into that... Problem was that some modules in the codebase referred to the components via

import { /* ... */  } from '@neos-project/react-ui-components';

This caused webpack to pull the components from '@neos-project/react-ui-components/lib-esm' rather than '@neos-project/react-ui-components/src', leading to the component modules being bundled twice.

The solution was to change those references to an explicit:

import { /* ... */  } from '@neos-project/react-ui-components/src';

Now the react-ui-components are only bundled once.

With that, I introduced the DialogManager class, which takes care of managing the closing behavior of dialogs when the escape key is pressed.

I then proceeded to also remove react-close-on-escape as well as react-portal from the dialog component. The former because it wasn't supposed to be there in the first place and the latter because react-dom has its own Portal-API, so react-portal is no longer needed.

After this, react-portal is only used in @neos-project/neos-ui somewhere in the Inspector implementation. Removing it there should be done in a separate PR though.

Long story short:

But if i press the escape (esc) key on my keyboard, it closes all overalys. Can we intercept the escape key as well?

Yep, that works now :D

Copy link
Member

@crydotsnake crydotsnake left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the improvements! Everything works as expected 💙

Some modules referred to the components via

```js
import { /* ... */  } from '@neos-project/react-ui-components';
```

This caused webpack to pull the components from
'@neos-project/react-ui-components/lib-esm' rather than
'@neos-project/react-ui-components/src', leading to the
component modules being bundled twice.

The solution was to add an alias for
'@neos-project/react-ui-components' to the root webpack
config, so that the components are always pulled from 'src/'
at build-time.
@grebaldi grebaldi force-pushed the bugfix/2925/dialog-click-outside branch from f221068 to ca2e1ac Compare June 21, 2023 11:54
@grebaldi grebaldi requested a review from mhsdesign June 21, 2023 11:56
@mhsdesign
Copy link
Member

mhsdesign commented Jun 21, 2023

Thanks for the adjustments @grebaldi ;) I will try this out locally soon.

of topic a bit, but what do you think about #3531, linking it here because its related.
We can continue discussing that over there ^^

@mhsdesign mhsdesign self-requested a review June 21, 2023 12:21
@grebaldi grebaldi force-pushed the bugfix/2925/dialog-click-outside branch from ca2e1ac to 4f309a8 Compare June 24, 2023 08:03
@bwaidelich
Copy link
Member

Sorry for being too lazy to test, but will this also affect the behavior of non-stacked dialogs?
So often I fill out a large creation dialog and close it by accident because I click next to it (or hit backspace to fix an input)

@grebaldi
Copy link
Contributor Author

grebaldi commented Jul 4, 2023

@bwaidelich
I'm afraid not. I've seen that #3531 has been reported (which I believe includes your description - except for the "backspace"-part). This PR only covers #2925, which came up during Media UI development.

I totally agree that #3531 needs to be addressed. Not sure whether this PR is the place to do so, though.

@bwaidelich
Copy link
Member

I'm afraid not. I've seen that #3531 has been reported

Ah right, I didn't see that.
I'll try to reproduce that backspace-issue and comment it there, thanks!

Copy link
Member

@mhsdesign mhsdesign left a comment

Choose a reason for hiding this comment

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

Thanks ;) Works as expected!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
7.3 Bug Label to mark the change as bugfix next-patch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove click-outside handling for Dialog
4 participants