[bug]: <body style="pointer-events: none;"
Describe the bug
I originally planned to implement a dialog box that pops up after clicking the right-click menu. The components used are ContextMenu and Dialog. When the dialog box pops up after clicking the menu, do nothing and click the x button in the upper right corner of the dialog box. Then, you cannot right-click on the same element again. Finally, I found that there is a style attribute "pointer-events: none;" on the body element.
Affected component/components
ContextMenu/Dialog
How to reproduce
- right click on
ContextMenuTrigger - click
ContextMenuItemand show aDialog - close the
xbutton of theDialog
The following is a full code example
import React, { useCallback, useState } from 'react';
import {
ContextMenu,
ContextMenuContent,
ContextMenuItem,
ContextMenuTrigger
} from '@/components/ui/context-menu';
import {
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogTitle
} from '@/components/ui/dialog';
import { Label } from '@/components/ui/label';
import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import { enablePointerEvents } from '@/lib/pointer-events';
export function TreeView() {
const [newDialogVisible, setNewDialogVisible] = useState(false);
const [inputValue, setInputValue] = useState('');
const onAdd = useCallback(() => {
setNewDialogVisible(true);
}, []);
const handleNewDialogClose = () => {
setNewDialogVisible(false);
// shadcn bug
enablePointerEvents();
};
const add = () => {
//
};
return (
<div className="pl-2 pr-2 flex flex-1">
<ContextMenu>
<ContextMenuTrigger className="flex flex-1 text-sm">
lorem
</ContextMenuTrigger>
<ContextMenuContent className="w-64">
<ContextMenuItem inset onClick={onAdd}>
New
</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>
<Dialog open={newDialogVisible}>
<DialogContent className="sm:max-w-[425px]" onClose={handleNewDialogClose}>
<DialogHeader>
<DialogTitle>New</DialogTitle>
</DialogHeader>
<Label className="flex items-center space-x-2 w-full">
<span>Name</span>
<Input
value={inputValue}
onChange={(event) => setInputValue(event.target.value.trim())}
className="flex-1"
/>
</Label>
<DialogFooter>
<Button type="submit" onClick={add}>Add</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
);
}
To solve this problem, I wrote a method called enablePointerEvents.
// lib/pointer-events.ts
export function enablePointerEvents() {
document.body.style.pointerEvents = '';
}
Codesandbox/StackBlitz link
No response
Logs
System Info
- system: mac os
- browser: chrome
Before submitting
- [x] I've made research efforts and searched the documentation
- [x] I've searched for existing issues
I would like to work on this. Can this issue be assigned to me?
I have the same problem, but just need to clear the.next and node_modules directories and then re-run npm i and npm run dev. I don't know why
version 1.1.7 of @radix-ui/react-dialog and @radix-ui/react-alert-dialog will encounter this issue, while version 1.1.6 will not.
version 1.1.7 of @radix-ui/react-dialog and @radix-ui/react-alert-dialog will encounter this issue, while version 1.1.6 will not.
"dependencies": {
"@radix-ui/react-dialog": "^1.1.6"
}
current version is 1.1.6 and The actual installed version is also 1.1.6.
I would like to work on this. Can this issue be assigned to me?
Thank you very much. I implemented a contextmenu component to replace it.
Property 'onClose' does not exist on type 'IntrinsicAttributes & DialogContentProps & RefAttributes<HTMLDivElement>'.ts(2322)... interface DialogProps { children?: React.ReactNode; open?: boolean; defaultOpen?: boolean; onOpenChange?(open: boolean): void; modal?: boolean; } ...
It is not the point.
i have same bug, i have Dialog inside Drodown, when i open dialog it add pointer-events: none; to body then dialog open store that styles and when that dialog closes it restores pointer-events: none; back to body so whole page is not clickable anymore :/
using
"@radix-ui/react-dialog": "^1.1.11",
"@radix-ui/react-dropdown-menu": "^2.1.6",
Easyiest FIX for me is setting modal={false} to DropdownMenu component until they fix it enjoy
It's a strange problem, the menu bar also has this phenomenon
i have same bug, i have Dialog inside Drodown, when i open dialog it add
pointer-events: none;to body then dialog open store that styles and when that dialog closes it restorespointer-events: none;back to body so whole page is not clickable anymore :/using
"@radix-ui/react-dialog": "^1.1.11", "@radix-ui/react-dropdown-menu": "^2.1.6",Easyiest FIX for me is setting
modal={false}toDropdownMenucomponent until they fix it enjoy
This method is ineffective for me, setting modal to false will cause click penetration.
version 1.1.7 of @radix-ui/react-dialog and @radix-ui/react-alert-dialog will encounter this issue, while version 1.1.6 will not.
"dependencies": { "@radix-ui/react-dialog": "^1.1.6" } current version is
1.1.6and The actual installed version is also1.1.6.
You should check the package-lock.json file to confirm the accurate version, rather than the package.json file.
Also encounter this problem. enablePointerEvents works as a workaround.
Also encounter this problem.
enablePointerEventsworks as a workaround.
where can we set this?
This issue can also occur when using uncontrolled Dialog in DropdownMenuItem
Yeah I am also facing this issue on 1.1.7 and I upgraded to 1.1.13 and still have it occuring.
modal={false}
Yeah this did the job thanks <DropdownMenu modal={false}>. No need to downgrade 1.1.13 works fine.
body{
pointer-events: all !important;
}
works for me
i have same bug, i have Dialog inside Drodown, when i open dialog it add
pointer-events: none;to body then dialog open store that styles and when that dialog closes it restorespointer-events: none;back to body so whole page is not clickable anymore :/using
"@radix-ui/react-dialog": "^1.1.11", "@radix-ui/react-dropdown-menu": "^2.1.6",Easyiest FIX for me is setting
modal={false}toDropdownMenucomponent until they fix it enjoy
Thanks!
I also faced this issue in DropdownMenu. I just added modal={false}, and it fixed the issue
<DropdownMenu modal={false}>
the same problem with AlertDialog
Clear install of npm packages helped me
I've upgraded the @radix-ui/react-dropdown-menu to 2.1.16 and reinstall the dropdown-menu component and back to work
pnpm dlx shadcn@latest add dropdown-menu
I ran into this issue when implementing a dialog in my case. I tried using modal={false}, but it made the area outside the dialog clickable. Using enablePointerEvents approach worked for my case.