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

[Dialog] body pointer-events: none remains after closing #1241

Closed
413n opened this issue Mar 14, 2022 · 77 comments · Fixed by #1401
Closed

[Dialog] body pointer-events: none remains after closing #1241

413n opened this issue Mar 14, 2022 · 77 comments · Fixed by #1401
Assignees
Labels

Comments

@413n
Copy link

413n commented Mar 14, 2022

Update of April 2024

This bug seems to be still appearing in newer versions. You will find some workarounds in the recent comments. ⬇️

Bug report

Current Behavior

With Dialog version 0.1.7 the pointer-events seems to remain on the body with the Chrome device emulator using a mobile device (e.g. iPad Air), while in the 0.1.6 it works fine.

Expected behavior

The pointer-events should always be removed from the body after the closing animation has finished.

Reproducible example

The 2 repos are identical, except the @radix-ui/react-dialog version:

Additional context

I forked the radix-ui/design-system repo on codesandbox to reproduce this bug keeping the original code but changing just the version of the @radix-ui/react-dialog.

Note: In the version 0.1.7, the problem should be solved by removing the close animation from the Content

@413n 413n changed the title [Dialog] Strange Pointer-events interaction [Dialog] Strange Pointer-events behavior Mar 14, 2022
@benoitgrelard benoitgrelard added the Type: Bug Confirmed bug label Apr 5, 2022
@benoitgrelard
Copy link
Collaborator

Hi @413n,

I can reproduce the bug using your sandboxes.
Thanks for reporting.

@janhoogeveen
Copy link

@benoitgrelard Seems like this is the same as #1236. Since this one has a working example already, should we close the other one? 👍🏻

@benoitgrelard
Copy link
Collaborator

I've been wondering too, but I haven't verified fully that it is indeed the same.
Once confirmed I will close one as duplicate.

@benoitgrelard benoitgrelard self-assigned this Apr 6, 2022
@benoitgrelard benoitgrelard changed the title [Dialog] Strange Pointer-events behavior [Dialog] body pointer-events: none remains after closing Apr 6, 2022
@benoitgrelard benoitgrelard added Priority: Urgent Urgent priority issue and removed Resolution: Backlog Priority: High High priority issue labels Apr 6, 2022
@HeatedGrace
Copy link

I use the AlertDialog and have the same question.
When AlertDialog.Trigger controls the open, body element can remove the 'pointer-events' normally.
But when i use the AlertDialog.Root open attribute, body element still keep the 'pointer-events' after close.

@benoitgrelard
Copy link
Collaborator

benoitgrelard commented May 12, 2022

I am still able to replicate this in main.
Some further observation: It only appears to be an issue when there's a close CSS animation on the Content part, ie. when it hands around.

Looking into it.

benoitgrelard added a commit that referenced this issue May 16, 2022
benoitgrelard added a commit that referenced this issue May 19, 2022
benoitgrelard added a commit that referenced this issue May 19, 2022
* [DismissableLayer] Fix pointer-events issues

Fixes #1241
Fixes #1263

* PR feedback

* Add cypress tests

* testing flake

* Fix flake?

* Fix false positive

* Copy change
luisorbaiceta pushed a commit to luisorbaiceta/primitives that referenced this issue Jul 21, 2022
* [DismissableLayer] Fix pointer-events issues

Fixes radix-ui#1241
Fixes radix-ui#1263

* PR feedback

* Add cypress tests

* testing flake

* Fix flake?

* Fix false positive

* Copy change
@PeerRich
Copy link

@benoitgrelard has this been fixed? we're experiencing this at calcom/cal.com#2328

@benoitgrelard
Copy link
Collaborator

Hey @PeerRich yes it has been fixed and released as part of the v1 release. Have you upgraded?

@PeerRich
Copy link

PeerRich commented Aug 1, 2022

@helenahedstrom
Copy link

helenahedstrom commented Dec 1, 2023

I got this issue when I opened a dialog on click in a dropdown menu.

I solved it before I found this thread by setting a timeout in the onclick function before opening the dialog so it has time to reset styling set by the dropdown menu.

Will however see if upgrades solves it so I wont need a timeout.

@robintown
Copy link

I am still experiencing this issue when using an animated menu in combination with an animated dialog, and I have identified the root cause: This occurs whenever you have multiple copies of @radix-ui/react-dismissable-layer in your tree, because that package relies on some global state to track when to remove the pointer-events rule from the <body>, and that global state is not shared across multiple copies of the module.

Others experiencing this issue: You can avoid it by making sure there is only 1 copy of @radix-ui/react-dismissable-layer in your build output.

  • First, try upgrading your dependencies. This may work if the versions of your @radix-ui packages were out of sync, causing your package manager to pull in multiple versions of @radix-ui/react-dismissable-layer.
  • If you're working with a linked package that also uses Radix Primitives, that might not be enough: there could still be other copies present in the node_modules of the linked package. Your best bet for dealing with this is to ask your build tool to de-duplicate @radix-ui/react-dismissable-layer, for example with Vite's resolve.dedupe option.

Maintainers: An ideal solution would be for @radix-ui/react-dismissable-layer to still function, even when multiple copies of the module are in use - I think this is achievable. Also, the reproduction case given by @hipstersmoothie in #1241 (comment) looks like it's showing yet another reason why pointer-events can get stuck?

@robintown
Copy link

Oh, and now I've found these related issues: #1088 #2355

@imhoffd
Copy link

imhoffd commented Jan 12, 2024

I am also running into this issue. I double-checked our bundle and confirmed that we only have one @radix-ui/react-dismissable-layer package. We are also on the latest versions of all Radix packages.

I forked @hipstersmoothie's codesandbox demo and updated the versions to demonstrate that it's still reproducible with the latest versions: https://codesandbox.io/p/sandbox/dropdownmenu-dialog-items-forked-94x39v?file=%2Fsrc%2FApp.js

Repro steps:

  1. Click "Actions"
  2. Click "Edit 2"
  3. Click again quickly to dismiss the dialog before the dropdown menu exit animation is complete
  4. Observe pointer-events: none still on body

I believe this is the best way to demonstrate the bug, although in our app we are seeing the bug occur with a dropdown within a dialog, both dismissed at the same time roughly equivalent exit animation durations.

@benoitgrelard Sorry for the ping, but we've seen this manifest in multiple ways (e.g dialog as child of dropdown, vice versa) and it does have a disastrous effect on the app as it renders it unresponsive to all pointer events.

In the meantime, I am going to implement this workaround (thanks @brandalx). This is what I ended up with in Dialog.tsx (just make sure the timeout is longer than your exit animations, but short enough to unfreeze your app before a user can interact):

  useEffect(() => {
    if (!open) {
      setTimeout(() => {
        document.body.style.pointerEvents = ''
      }, 500)
    }
  }, [open])

Thank you to the maintainers and contributors of Radix! We are thoroughly pleased thus far.

@mardausdennis
Copy link

I forked @hipstersmoothie's codesandbox demo and updated the versions to demonstrate that it's still reproducible with the latest versions: https://codesandbox.io/p/sandbox/dropdownmenu-dialog-items-forked-94x39v?file=%2Fsrc%2FApp.js

Repro steps:

  1. Click "Actions"
  2. Click "Edit 2"
  3. Click again quickly to dismiss the dialog before the dropdown menu exit animation is complete
  4. Observe pointer-events: none still on body

I believe this is the best way to demonstrate the bug, although in our app we are seeing the bug occur with a dropdown within a dialog, both dismissed at the same time roughly equivalent exit animation durations.

In the meantime, I am going to implement this workaround (thanks @brandalx). This is what I ended up with in Dialog.tsx (just make sure the timeout is longer than your exit animations, but short enough to unfreeze your app before a user can interact):

  useEffect(() => {
    if (!open) {
      setTimeout(() => {
        document.body.style.pointerEvents = ''
      }, 500)
    }
  }, [open])

I'm experiencing the same issue in my project, though it happens with a popover inside a modal dialog. When I open the popover and then close the dialog, everything becomes unresponsive, just as you described.

The workaround you mentioned also works for me, but I agree it seems a bit hacky. It would be ideal to get this bug fixed properly as soon as possible, especially since I see it's been around for a while.

As developers, having these basic functions work reliably is crucial so we don't negatively impact the user experience. I hope the Radix devs can get this sorted out soon.

@JRhodes95
Copy link

Hey folks - just seconding that this appears to be an ongoing issue.

Don't have a perfect repro example but I'm using the dropdown as an actions menu on a table.
A 'delete' action triggers an alert dialog but when closing it the pointer-events:none remains on the body.
Have checked and all radix deps are up to date.

Appreciate your work on Radix but would be awesome if you could take a look at this one!

Thanks

@sturdynut
Copy link

Having this issue as well with the latest version. To fix, I found that you can simply wire up the onOpenChange and update the body pointerEvents there. See example below.

...
const handleOnOpenChange = (open: boolean) => {
    // Bug fix: Radix UI leaves pointer-events none on body when dialog is closed
    if (open === false) {
      document.body.style.pointerEvents = "auto";
    }
  };

  return (
    <Dialog.Root onOpenChange={handleOnOpenChange}>
...

@hwride
Copy link

hwride commented Apr 26, 2024

In my case I have found this happens when you attach a close animation to the overlay, and that it also causes the overlay not to be removed. This doesn't happen without the close animation. Using version 1.0.5.

@hwride
Copy link

hwride commented Apr 26, 2024

Hi @benoitgrelard, should this one be re-opened? It seems it's still happening to quite a few people. Thanks.

@swiftpaca
Copy link

Hi @benoitgrelard, this is still an issue. Any updates/progress? Appreciate the help.

@Abduganeoff
Copy link

Abduganeoff commented May 23, 2024

I experienced the same issue while using the radix DropdownMenu and Dialog together

setting modal={false} on DropdownMenu.Root fixes it for me https://www.radix-ui.com/docs/primitives/components/dropdown-menu#root

@dimaMachina I was also having the same issue with Dialog and DropdownMenu. you are just brilliant 🚀

@dalalRohit
Copy link

dalalRohit commented Jul 16, 2024

setting modal={false} on <DropdownMenu /> solved it for me.

@K-Mistele
Copy link

Setting modal={false} doesn't work for me because the dialog closes instantly again - probably because I'm using it in conjunction with a dropdown menu. It seems like this is a regression?

@sahanatvessel
Copy link

why was this issue closed?

@sahanatvessel
Copy link

related #2122

@Notmeomg
Copy link

Notmeomg commented Aug 18, 2024

This issue was resolved for me by aligning package versions. I did this after reading #1088.

@kacem22
Copy link

kacem22 commented Aug 20, 2024

For us, this was being caused by a dialog being opened by a dropdown.

Two possible fixes for us were:

  • Update @radix-ui/react-dropdown-menu to 2.0.6
  • Add modal={false} to the dropdowns (not needed if you update)

it works for me thank you @TranquilMarmot

@HussainAhmadDev
Copy link

HussainAhmadDev commented Sep 5, 2024

The simple css solution is to just give pointer-events: auto to the other element that got broken due to the body pointer-events: none easy hack 😊

@jvenus99
Copy link

jvenus99 commented Oct 1, 2024

Hi Guys!
I found a other solution for this problem. I just install a dependency @radix-ui/react-dismissable-layer
So, do npm i @radix-ui/react-dismissable-layer and rerun your project.

@Aslam97
Copy link

Aslam97 commented Oct 3, 2024

Hi Guys! I found a other solution for this problem. I just install a dependency @radix-ui/react-dismissable-layer So, do npm i @radix-ui/react-dismissable-layer and rerun your project.

this does work if I remove node_modules and lock file.

@efeguerrero
Copy link

Hi Guys! I found a other solution for this problem. I just install a dependency @radix-ui/react-dismissable-layer So, do npm i @radix-ui/react-dismissable-layer and rerun your project.

This package is the problem when you have different versions of it as dependencies of your radix-ui elements (check package-lock.json).

My solution was deleting node_modules and package-lock.json and installing everything fresh again.

Now all @radix-ui/react-dismissable-layer versions used by radix elements are the same and the issue is gone.

@dytra
Copy link

dytra commented Oct 7, 2024

In my case I'm using <ContextMenu /> for triggering the dialog.
Setting the modal prop to false solves the issue

<ContextMenu key={item.fileId} modal={false}>
...
</ContextMenu>

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

Successfully merging a pull request may close this issue.