-
Notifications
You must be signed in to change notification settings - Fork 5k
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
[bug]: After the mobile sidebar is opened and the page is redirected, the style="pointer-events: none;" in the body affects the click events on the redirected page. #6227
Comments
I used this method to solve my problem, but I'm not sure if it's the best solution. |
@Amazing-ah just to be clear why are you using Then from the docs DropdownMenuItem should be wrapped in DropdownMenu <DropdownMenu>
<DropdownMenuTrigger>Open</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuLabel>My Account</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuItem>Profile</DropdownMenuItem>
<DropdownMenuItem>Billing</DropdownMenuItem>
<DropdownMenuItem>Team</DropdownMenuItem>
<DropdownMenuItem>Subscription</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu> I just tried that and its working as expected |
Thank you for the response. The
|
This works fine for me. You might want to read further here //layout.tsx
"use client";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarProvider, SidebarTrigger } from "@/components/ui/sidebar";
import { BadgeCheck, ChevronsUpDown, LogOut } from "lucide-react";
import { useRouter } from "next/navigation";
import { useState } from "react";
import "./globals.css";
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
const [user, setUser] = useState({
name: "test name",
email: "[email protected]",
});
const [isMobile, setIsMobile] = useState(false);
const router = useRouter();
return (
<html lang="en">
<body>
<SidebarProvider>
<SidebarMenu>
<SidebarMenuItem>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<SidebarMenuButton
size="lg"
className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground">
{/* <Avatar className="h-8 w-8 rounded-lg">
<AvatarImage src={user.avatar} alt={user.name} />
<AvatarFallback className="rounded-lg">CN</AvatarFallback>
</Avatar> */}
<div className="grid flex-1 text-left text-sm leading-tight">
<span className="truncate font-semibold">{user.name}</span>
<span className="truncate text-xs">{user.email}</span>
</div>
<ChevronsUpDown className="ml-auto size-4" />
</SidebarMenuButton>
</DropdownMenuTrigger>
<DropdownMenuContent
className="w-[--radix-dropdown-menu-trigger-width] min-w-56 rounded-lg"
side={isMobile ? "bottom" : "right"}
align="end"
sideOffset={4}>
<DropdownMenuLabel className="p-0 font-normal">
<div className="flex items-center gap-2 px-1 py-1.5 text-left text-sm">
{/* <Avatar className="h-8 w-8 rounded-lg">
<AvatarImage src={user.avatar} alt={user.name} />
<AvatarFallback className="rounded-lg">CN</AvatarFallback>
</Avatar> */}
<div className="grid flex-1 text-left text-sm leading-tight">
<span className="truncate font-semibold">{user.name}</span>
<span className="truncate text-xs">{user.email}</span>
</div>
</div>
</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<DropdownMenuItem
onClick={async () => {
// document.body.style.pointerEvents = 'auto';
router.push("/");
}}>
{/* <Undo2 /> */}
Return to homepage
</DropdownMenuItem>
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<DropdownMenuItem
onClick={() => {
router.push("/admin/account");
}}>
<BadgeCheck />
Account Settings{" "}
</DropdownMenuItem>
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={async () => {
console.log("clicked 3");
// document.body.style.pointerEvents = 'auto';
// await logout();
}}>
<LogOut />
Log out
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</SidebarMenuItem>
</SidebarMenu>
<main>
<SidebarTrigger />
{children}
</main>
</SidebarProvider>
</body>
</html>
);
} // home page
"use client";
export default function Component() {
return (
<p>
home oage
<button onClick={() => console.log("click works just fine")}>click me</button>
</p>
);
} //admin/account
"use client";
export default function Component() {
return (
<p>
admin page
<button onClick={() => console.log("click works just fine")}>click me</button>
</p>
);
}
|
Describe the bug
On the mobile page, after opening the sidebar, a link was redirected. After the redirect, the style="pointer-events: none;" in the body was not reset, affecting the page's click events.
Affected component/components
Sidebar
How to reproduce
NavUser.tsx
then in body
<body style='pointer-events:none;'></body>
Codesandbox/StackBlitz link
No response
Logs
No response
System Info
Before submitting
The text was updated successfully, but these errors were encountered: