fix: prevent drag listeners from blocking navigation clicks in sidebar #5567

Separated dnd-kit drag handlers (attributes/listeners) from ListItemButton
to ListItemIcon only. Previously, long-press or rapid clicks on nav items
would trigger drag detection and cancel the click event, causing the item
to visually highlight but fail to navigate.

Changes:
- Moved sortable attributes/listeners to icon elements only
- ListItemButton now handles pure navigation clicks without interference
- Drag handle cursor ('grab') remains on icons when sortable is enabled

Fixes issue where sidebar tabs would "go dark" without actual route change.
This commit is contained in:
Tunglies 2025-11-23 11:47:27 +08:00
parent cbab199f80
commit ddd24eb3ac
No known key found for this signature in database
GPG Key ID: B9B01B389469B3E8

View File

@ -6,11 +6,11 @@ import {
alpha,
ListItem,
ListItemButton,
ListItemText,
ListItemIcon,
ListItemText,
} from "@mui/material";
import type { CSSProperties, ReactNode } from "react";
import { useMatch, useResolvedPath, useNavigate } from "react-router";
import { useMatch, useNavigate, useResolvedPath } from "react-router";
import { useVerge } from "@/hooks/use-verge";
@ -58,7 +58,7 @@ export const LayoutItem = (props: Props) => {
paddingLeft: 1,
paddingRight: 1,
marginRight: 1.25,
cursor: sortable && !sortable.disabled ? "grab" : "pointer",
cursor: "pointer",
"& .MuiListItemText-primary": {
color: "text.primary",
fontWeight: "700",
@ -70,7 +70,6 @@ export const LayoutItem = (props: Props) => {
? alpha(primary.main, 0.15)
: alpha(primary.main, 0.35);
const color = mode === "light" ? "#1f1f1f" : "#ffffff";
return {
"&.Mui-selected": { bgcolor },
"&.Mui-selected:hover": { bgcolor },
@ -79,15 +78,29 @@ export const LayoutItem = (props: Props) => {
},
]}
onClick={() => navigate(to)}
{...(attributes ?? {})}
{...(listeners ?? {})}
>
{(menu_icon === "monochrome" || !menu_icon) && (
<ListItemIcon sx={{ color: "text.primary", marginLeft: "6px" }}>
<ListItemIcon
sx={{
color: "text.primary",
marginLeft: "6px",
cursor: sortable && !sortable.disabled ? "grab" : "inherit",
}}
{...(attributes ?? {})}
{...(listeners ?? {})}
>
{icon[0]}
</ListItemIcon>
)}
{menu_icon === "colorful" && <ListItemIcon>{icon[1]}</ListItemIcon>}
{menu_icon === "colorful" && (
<ListItemIcon
sx={{ cursor: sortable && !sortable.disabled ? "grab" : "inherit" }}
{...(attributes ?? {})}
{...(listeners ?? {})}
>
{icon[1]}
</ListItemIcon>
)}
<ListItemText
sx={{
textAlign: "center",