Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-8771 fix(sidebar): use the shared drag click guard in pinned, views and projects (#10124)

Jiayuan Zhang4e3c56b50f95
diff --git a/packages/views/layout/app-rail.tsx b/packages/views/layout/app-rail.tsx
index ddc178d295..5d5f198b2a 100644
--- a/packages/views/layout/app-rail.tsx
+++ b/packages/views/layout/app-rail.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useCallback, useEffect, useMemo, useRef } from "react";
+import { useCallback, useMemo } from "react";
import { useQuery } from "@tanstack/react-query";
import {
DndContext,
@@ -41,6 +41,7 @@ import { useTeamAgentStatus } from "./panels/team-status";
import { RAIL_ICON_BUTTON_CLASS } from "./rail-styles";
import { RailWorkspaces } from "./rail-workspaces";
import { routeIconForPath } from "./route-icon-components";
+import { useDragClickGuard } from "./use-drag-click-guard";
type RailBadge =
| { kind: "count"; value: number; tone: "brand" | "neutral" }
@@ -195,37 +196,6 @@ function SortableRailItem({ id, children }: { id: RailSpaceId; children: React.R
}
const DRAG_MODIFIERS = [restrictToVerticalAxis, restrictToFirstScrollableAncestor];
-// dnd-kit keeps swallowing clicks for this long after a drag ends.
-const DRAG_CLICK_GUARD_MS = 50;
-
-function preventDefault(event: Event) {
- event.preventDefault();
-}
-
-/**
- * The release that ends a drag must not also open the space. Once a drag
- * activates, dnd-kit stops that click's propagation at the document but
- * leaves its default, so the link would still navigate natively. A window
- * capture listener runs first and cancels it.
- */
-function useDragClickGuard() {
- const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
- const disarm = useCallback(() => {
- if (timer.current) clearTimeout(timer.current);
- timer.current = null;
- window.removeEventListener("click", preventDefault, true);
- }, []);
- useEffect(() => disarm, [disarm]);
- return {
- arm: useCallback(() => {
- disarm();
- window.addEventListener("click", preventDefault, true);
- }, [disarm]),
- release: useCallback(() => {
- timer.current = setTimeout(disarm, DRAG_CLICK_GUARD_MS);
- }, [disarm]),
- };
-}
/**
* The app rail: workspaces, New issue and search, the five spaces in the
diff --git a/packages/views/layout/panels/pinned-section.test.tsx b/packages/views/layout/panels/pinned-section.test.tsx
index 0f1b18bf2f..811da86c83 100644
--- a/packages/views/layout/panels/pinned-section.test.tsx
+++ b/packages/views/layout/panels/pinned-section.test.tsx
@@ -26,20 +26,6 @@ const state = vi.hoisted(() => ({
vi.mock("@multica/core/issue-statuses/hooks", () => ({
useIssueStatuses: () => buildIssueStatusCatalog([]),
}));
-vi.mock("@dnd-kit/core", () => ({
- DndContext: ({ children }: { children: ReactNode }) => <>{children}</>,
- PointerSensor: vi.fn(),
- closestCenter: vi.fn(),
- useSensor: vi.fn(),
- useSensors: vi.fn(),
-}));
-vi.mock("@dnd-kit/sortable", () => ({
- SortableContext: ({ children }: { children: ReactNode }) => <>{children}</>,
- useSortable: () => ({ attributes: {}, listeners: {}, setNodeRef: vi.fn() }),
- verticalListSortingStrategy: vi.fn(),
- arrayMove: vi.fn(),
-}));
-vi.mock("@dnd-kit/utilities", () => ({ CSS: { Translate: { toString: () => undefined } } }));
vi.mock("../../navigation", () => ({
AppLink: ({ children, href, ...props }: { children: ReactNode; href: string } & React.ComponentProps<"a">) => (
<a href={href} {...props}>
@@ -201,6 +187,29 @@ describe("PinnedSection", () => {
expect((await iconSlot())?.matches("svg")).toBe(true);
});
+ // dnd-kit stops the release's click at the document without cancelling
+ // it. Where React listens below the document (Desktop), it never sees that
+ // click, so the row must not wait for it before opening on the next one.
+ it("does not open the pin released at the end of a drag, and opens it on the next click", async () => {
+ state.detail = {
+ isPending: false,
+ isError: false,
+ data: { identifier: "MUL-123", title: "Keep this pin", status: "todo" },
+ error: null,
+ };
+ renderWithI18n(<Harness pathname="/acme/issues" />);
+ const row = (await screen.findByText("Keep this pin")).closest("a")!;
+ const pointer = { isPrimary: true, button: 0, clientX: 30, clientY: 100 };
+ fireEvent.pointerDown(row, pointer);
+ fireEvent.pointerMove(document, { ...pointer, clientY: 110 });
+ fireEvent.pointerUp(document, { ...pointer, clientY: 110 });
+
+ expect(fireEvent.click(row)).toBe(false);
+
+ await new Promise((resolve) => setTimeout(resolve, 60));
+ expect(fireEvent.click(row)).toBe(true);
+ });
+
it("renders nothing without pins", () => {
state.pins = [];
const { container } = renderWithI18n(<Harness pathname="/acme/issues" />);
diff --git a/packages/views/layout/panels/pinned-section.tsx b/packages/views/layout/panels/pinned-section.tsx
index 7144b279ba..f57497d84d 100644
--- a/packages/views/layout/panels/pinned-section.tsx
+++ b/packages/views/layout/panels/pinned-section.tsx
@@ -32,6 +32,7 @@ import { useStatusLabel } from "../../issues/utils/status-label";
import { ProjectIcon } from "../../projects/components/project-icon";
import { useT } from "../../i18n";
import { PANEL_ROW_CLASS, PanelList, PanelSection, isPathWithin, panelRowStateClass } from "../panel-nav";
+import { useDragClickGuard } from "../use-drag-click-guard";
import {
ISSUE_ROW_LINK_CLASS,
IssueAgentBadge,
@@ -126,13 +127,20 @@ export function PinnedSection({ pins, wsId }: { pins: PanelPins; wsId: string })
const { visible, displayed, expanded, setExpanded, setLocalPinned, isDraggingRef, viewPins, isPinActive } = pins;
const collapsed = useSidebarTreeStore((s) => s.pinnedCollapsed);
const setCollapsed = useSidebarTreeStore((s) => s.setPinnedCollapsed);
+ const { arm: armClickGuard, release: releaseClickGuard } = useDragClickGuard();
const handleDragStart = useCallback(() => {
isDraggingRef.current = true;
- }, [isDraggingRef]);
+ armClickGuard();
+ }, [armClickGuard, isDraggingRef]);
+ const handleDragCancel = useCallback(() => {
+ isDraggingRef.current = false;
+ releaseClickGuard();
+ }, [isDraggingRef, releaseClickGuard]);
const handleDragEnd = useCallback(
(event: DragEndEvent) => {
isDraggingRef.current = false;
+ releaseClickGuard();
const { active, over } = event;
if (!over || active.id === over.id) return;
const oldIndex = visible.findIndex((pin) => pin.id === active.id);
@@ -142,7 +150,7 @@ export function PinnedSection({ pins, wsId }: { pins: PanelPins; wsId: string })
setLocalPinned(reordered);
reorderPins.mutate([...reordered, ...viewPins]);
},
- [isDraggingRef, reorderPins, setLocalPinned, viewPins, visible],
+ [isDraggingRef, releaseClickGuard, reorderPins, setLocalPinned, viewPins, visible],
);
if (visible.length === 0) return null;
@@ -153,7 +161,13 @@ export function PinnedSection({ pins, wsId }: { pins: PanelPins; wsId: string })
collapsed={collapsed}
onCollapsedChange={setCollapsed}
>
- <DndContext sensors={sensors} collisionDetection={closestCenter} onDragStart={handleDragStart} onDragEnd={handleDragEnd}>
+ <DndContext
+ sensors={sensors}
+ collisionDetection={closestCenter}
+ onDragStart={handleDragStart}
+ onDragEnd={handleDragEnd}
+ onDragCancel={handleDragCancel}
+ >
<SortableContext items={displayed.map((pin) => pin.id)} strategy={verticalListSortingStrategy}>
<PanelList>
{displayed.map((pin) => (
@@ -195,7 +209,6 @@ function SortablePinItem({
running = false,
unread = false,
trailing,
- onNavigate,
issue,
}: {
pin: PinnedItem;
@@ -209,18 +222,11 @@ function SortablePinItem({
/** Brightens the label while the issue has an unread agent result. */
unread?: boolean;
trailing?: React.ReactNode;
- /** Runs on a real click (not a drag-release) before navigation. */
- onNavigate?: () => void;
/** A pinned issue's row opens the issue context menu on right-click. */
issue?: Issue;
}) {
const { t } = useT("layout");
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: pin.id });
- const wasDragged = useRef(false);
-
- useEffect(() => {
- if (isDragging) wasDragged.current = true;
- }, [isDragging]);
const row = (
<div
@@ -239,14 +245,6 @@ function SortablePinItem({
newTabTitle={label}
draggable={false}
aria-current={active ? "page" : undefined}
- onClick={(event) => {
- if (wasDragged.current) {
- wasDragged.current = false;
- event.preventDefault();
- return;
- }
- onNavigate?.();
- }}
className={cn(ISSUE_ROW_LINK_CLASS, "gap-2.5")}
>
<ShimmerText
diff --git a/packages/views/layout/panels/views-section.test.tsx b/packages/views/layout/panels/views-section.test.tsx
index bc954d5605..57dc2913ea 100644
--- a/packages/views/layout/panels/views-section.test.tsx
+++ b/packages/views/layout/panels/views-section.test.tsx
@@ -17,19 +17,6 @@ const actions = vi.hoisted(() => ({
vi.mock("../../issue-views/use-view-actions", () => ({ useIssueViewActions: () => actions }));
vi.mock("../../issue-views/delete-view-dialog", () => ({ DeleteViewDialog: () => null }));
-vi.mock("@dnd-kit/core", () => ({
- DndContext: ({ children }: { children: ReactNode }) => <>{children}</>,
- PointerSensor: vi.fn(),
- closestCenter: vi.fn(),
- useSensor: vi.fn(),
- useSensors: vi.fn(),
-}));
-vi.mock("@dnd-kit/sortable", () => ({
- SortableContext: ({ children }: { children: ReactNode }) => <>{children}</>,
- useSortable: () => ({ listeners: {}, setNodeRef: vi.fn(), setActivatorNodeRef: vi.fn() }),
- verticalListSortingStrategy: vi.fn(),
- arrayMove: vi.fn(),
-}));
vi.mock("@multica/ui/components/common/tooltip-hint", () => ({
TooltipHint: ({ children }: { children: ReactNode }) => <>{children}</>,
}));
@@ -128,6 +115,27 @@ describe("ViewsSection", () => {
expect(screen.getByRole("button", { name: "Issues in Not done" })).toHaveAttribute("aria-expanded", "false");
});
+ // dnd-kit stops the release's click at the document without cancelling
+ // it. Where React listens below the document (Desktop), it never sees that
+ // click, so the row must not wait for it before opening on the next one.
+ it("does not open the view released at the end of a drag, and opens it on the next click", async () => {
+ actions.sidebar.items = [{ id: "view:v1", kind: "view", view: SAVED_VIEW }];
+ const push = vi.fn();
+ renderSection(makeAdapter({ push }));
+ const row = screen.getByRole("link", { name: "Not done" });
+ const pointer = { isPrimary: true, button: 0, clientX: 30, clientY: 100 };
+ fireEvent.pointerDown(row, pointer);
+ fireEvent.pointerMove(document, { ...pointer, clientY: 110 });
+ fireEvent.pointerUp(document, { ...pointer, clientY: 110 });
+
+ expect(fireEvent.click(row)).toBe(false);
+ expect(push).not.toHaveBeenCalled();
+
+ await new Promise((resolve) => setTimeout(resolve, 60));
+ fireEvent.click(row);
+ expect(push).toHaveBeenCalledWith("/acme/issues?view=v1");
+ });
+
describe("view state follows where the click actually navigates", () => {
beforeEach(() => {
actions.sidebar.items = [
diff --git a/packages/views/layout/panels/views-section.tsx b/packages/views/layout/panels/views-section.tsx
index 69e2ac2f0a..63618995ef 100644
--- a/packages/views/layout/panels/views-section.tsx
+++ b/packages/views/layout/panels/views-section.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useCallback, useEffect, useId, useRef, useState } from "react";
+import { useCallback, useId, useRef, useState } from "react";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { useStore } from "zustand";
import { DndContext, PointerSensor, closestCenter, useSensor, useSensors, type DragEndEvent } from "@dnd-kit/core";
@@ -63,6 +63,7 @@ import { useBuiltinViewNavigation } from "../../issue-views/builtin-views";
import { useNavigation } from "../../navigation";
import { useT } from "../../i18n";
import { PANEL_ROW_CLASS, PanelCount, PanelLink, PanelList, PanelSection, isPathWithin, panelRowStateClass } from "../panel-nav";
+import { useDragClickGuard } from "../use-drag-click-guard";
import { SidebarIssueList, TREE_ROW_BUTTON_CLASS, TreeRow } from "./sidebar-tree";
const DRAG_MODIFIERS = [restrictToVerticalAxis, restrictToFirstScrollableAncestor];
@@ -114,9 +115,11 @@ export function ViewsSection({
const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 5 } }));
const collapsed = useSidebarTreeStore((s) => s.viewsCollapsed);
const setCollapsed = useSidebarTreeStore((s) => s.setViewsCollapsed);
+ const { arm: armClickGuard, release: releaseClickGuard } = useDragClickGuard();
const onDragEnd = useCallback(
({ active, over }: DragEndEvent) => {
+ releaseClickGuard();
if (!over || active.id === over.id) return;
const ids = items.map((item) => item.id);
const from = ids.indexOf(String(active.id));
@@ -124,7 +127,7 @@ export function ViewsSection({
if (from === -1 || to === -1) return;
reorder(arrayMove(ids, from, to));
},
- [items, reorder],
+ [items, releaseClickGuard, reorder],
);
return (
@@ -153,7 +156,14 @@ export function ViewsSection({
</IconButton>
}
>
- <DndContext sensors={sensors} collisionDetection={closestCenter} modifiers={DRAG_MODIFIERS} onDragEnd={onDragEnd}>
+ <DndContext
+ sensors={sensors}
+ collisionDetection={closestCenter}
+ modifiers={DRAG_MODIFIERS}
+ onDragStart={armClickGuard}
+ onDragEnd={onDragEnd}
+ onDragCancel={releaseClickGuard}
+ >
<SortableContext items={items.map((item) => item.id)} strategy={verticalListSortingStrategy}>
<PanelList>
{items.map((item) => (
@@ -226,16 +236,10 @@ function usePrefetch(wsId: string, source: string, request: SidebarIssuesRequest
interface DragBindings {
rowRef: (node: HTMLElement | null) => void;
listeners: ReturnType<typeof useSortable>["listeners"];
- /** True right after a drag, so the release does not also navigate. */
- consumeDrag: () => boolean;
}
function SortableViewRow({ id, children }: { id: string; children: (drag: DragBindings) => React.ReactNode }) {
const { listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging } = useSortable({ id });
- const wasDragged = useRef(false);
- useEffect(() => {
- if (isDragging) wasDragged.current = true;
- }, [isDragging]);
return (
<li
ref={setNodeRef}
@@ -247,11 +251,6 @@ function SortableViewRow({ id, children }: { id: string; children: (drag: DragBi
{children({
rowRef: setActivatorNodeRef,
listeners,
- consumeDrag: () => {
- if (!wasDragged.current) return false;
- wasDragged.current = false;
- return true;
- },
})}
</li>
);
@@ -378,9 +377,6 @@ function BuiltinViewRow({
event.preventDefault();
setMenuOpen(true);
}}
- onNavigate={(event) => {
- if (drag.consumeDrag()) event.preventDefault();
- }}
onNavigateInPlace={() => builtinNav.prepare(builtin)}
trailing={
<RowMenu label={t(($) => $.panels.work.view_actions, { name: label })} open={menuOpen} onOpenChange={setMenuOpen}>
@@ -475,9 +471,6 @@ function UnreadViewRow({
event.preventDefault();
setMenuOpen(true);
}}
- onNavigate={(event) => {
- if (drag.consumeDrag()) event.preventDefault();
- }}
onNavigateInPlace={() => setActive(target.containerKey, UNREAD_VIEW_ID)}
trailing={
// The menu button takes the count's place, so the row never reflows.
@@ -604,9 +597,6 @@ function SavedViewRow({
event.preventDefault();
setMenuOpen(true);
}}
- onNavigate={(event) => {
- if (drag.consumeDrag()) event.preventDefault();
- }}
onNavigateInPlace={() => setActive(target.containerKey, view.id)}
trailing={
<RowMenu label={t(($) => $.panels.work.view_actions, { name: view.name })} open={menuOpen} onOpenChange={setMenuOpen}>
diff --git a/packages/views/layout/panels/work-tree.test.tsx b/packages/views/layout/panels/work-tree.test.tsx
index 53f5b3e6c9..f2391f61f5 100644
--- a/packages/views/layout/panels/work-tree.test.tsx
+++ b/packages/views/layout/panels/work-tree.test.tsx
@@ -29,16 +29,16 @@ vi.mock("@multica/core/issues/stores/create-mode-store", () => ({
const dnd = vi.hoisted(() => ({ onDragEnd: undefined as ((event: DragEndEvent) => void) | undefined }));
-vi.mock("@dnd-kit/core", () => ({
- DndContext: ({ children, onDragEnd }: { children: ReactNode; onDragEnd: (event: DragEndEvent) => void }) => {
- dnd.onDragEnd = onDragEnd;
- return <>{children}</>;
- },
- PointerSensor: vi.fn(),
- closestCenter: vi.fn(),
- useSensor: vi.fn(),
- useSensors: vi.fn(),
-}));
+vi.mock("@dnd-kit/core", async (importOriginal) => {
+ const actual = await importOriginal<typeof import("@dnd-kit/core")>();
+ return {
+ ...actual,
+ DndContext: (props: React.ComponentProps<typeof actual.DndContext>) => {
+ dnd.onDragEnd = props.onDragEnd;
+ return <actual.DndContext {...props} />;
+ },
+ };
+});
vi.mock("@multica/core/issue-statuses/hooks", () => ({
useIssueStatuses: () => buildIssueStatusCatalog([]),
}));
@@ -144,6 +144,23 @@ describe("ProjectsSection", () => {
expect(prefs.projects.ordering).toBe("manual");
});
+ // dnd-kit stops the release's click at the document without cancelling
+ // it. Where React listens below the document (Desktop), it never sees that
+ // click, so the row must not wait for it before opening on the next one.
+ it("does not open the project released at the end of a drag, and opens it on the next click", async () => {
+ renderSection();
+ const row = screen.getByRole("link", { name: "Mobile" });
+ const pointer = { isPrimary: true, button: 0, clientX: 30, clientY: 100 };
+ fireEvent.pointerDown(row, pointer);
+ fireEvent.pointerMove(document, { ...pointer, clientY: 110 });
+ fireEvent.pointerUp(document, { ...pointer, clientY: 110 });
+
+ expect(fireEvent.click(row)).toBe(false);
+
+ await new Promise((resolve) => setTimeout(resolve, 60));
+ expect(fireEvent.click(row)).toBe(true);
+ });
+
it("creates an issue in a project from its row", () => {
renderSection();
fireEvent.click(screen.getByRole("button", { name: "New issue in Mobile" }));
diff --git a/packages/views/layout/panels/work-tree.tsx b/packages/views/layout/panels/work-tree.tsx
index e49c8de4d0..24fc87341c 100644
--- a/packages/views/layout/panels/work-tree.tsx
+++ b/packages/views/layout/panels/work-tree.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useCallback, useEffect, useId, useMemo, useRef, useSyncExternalStore } from "react";
+import { useCallback, useId, useMemo, useRef, useSyncExternalStore } from "react";
import { useQueryClient } from "@tanstack/react-query";
import { DndContext, PointerSensor, closestCenter, useSensor, useSensors, type DragEndEvent } from "@dnd-kit/core";
import { SortableContext, arrayMove, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
@@ -36,6 +36,7 @@ import {
panelRowStateClass,
} from "../panel-nav";
import { ProjectIcon } from "../../projects/components/project-icon";
+import { useDragClickGuard } from "../use-drag-click-guard";
import { ProjectsSectionSettings } from "./sidebar-settings";
import { SidebarIssueList, TreeRow } from "./sidebar-tree";
@@ -146,9 +147,11 @@ export function ProjectsSection({
const { projectSettings, issueSettings, projectOrder } = useSidebarProjectPrefs(wsId);
const updatePrefs = useUpdateSidebarProjectPrefs(wsId);
const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 5 } }));
+ const { arm: armClickGuard, release: releaseClickGuard } = useDragClickGuard();
const onDragEnd = useCallback(
({ active, over }: DragEndEvent) => {
+ releaseClickGuard();
if (!over || active.id === over.id) return;
const ids = projects.map((project) => project.id);
const from = ids.indexOf(String(active.id));
@@ -161,7 +164,7 @@ export function ProjectsSection({
projectSettings: { ordering: "manual" },
});
},
- [projects, projectOrder, updatePrefs],
+ [projects, projectOrder, releaseClickGuard, updatePrefs],
);
return (
@@ -183,7 +186,14 @@ export function ProjectsSection({
</>
}
>
- <DndContext sensors={sensors} collisionDetection={closestCenter} modifiers={DRAG_MODIFIERS} onDragEnd={onDragEnd}>
+ <DndContext
+ sensors={sensors}
+ collisionDetection={closestCenter}
+ modifiers={DRAG_MODIFIERS}
+ onDragStart={armClickGuard}
+ onDragEnd={onDragEnd}
+ onDragCancel={releaseClickGuard}
+ >
<SortableContext items={projects.map((project) => project.id)} strategy={verticalListSortingStrategy}>
<PanelList>
{projects.map((project) => (
@@ -270,10 +280,6 @@ function ProjectTreeItem({
const prefetch = usePrefetch(wsId, source, params);
const { listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging } = useSortable({ id: project.id });
- const wasDragged = useRef(false);
- useEffect(() => {
- if (isDragging) wasDragged.current = true;
- }, [isDragging]);
return (
<li
@@ -300,11 +306,6 @@ function ProjectTreeItem({
listId={listId}
toggleLabel={t(($) => $.panels.work.project_issues, { name: project.title })}
onPrefetch={prefetch}
- onNavigate={(event) => {
- if (!wasDragged.current) return;
- wasDragged.current = false;
- event.preventDefault();
- }}
trailing={
// The button takes the count's place on hover, so the row never reflows.
<span className="relative flex h-5 min-w-5 items-center justify-end">
diff --git a/packages/views/layout/use-drag-click-guard.ts b/packages/views/layout/use-drag-click-guard.ts
new file mode 100644
index 0000000000..fbf5823a30
--- /dev/null
+++ b/packages/views/layout/use-drag-click-guard.ts
@@ -0,0 +1,39 @@
+"use client";
+
+import { useCallback, useEffect, useRef } from "react";
+
+// dnd-kit keeps swallowing clicks for this long after a drag ends.
+const DRAG_CLICK_GUARD_MS = 50;
+
+function preventDefault(event: Event) {
+ event.preventDefault();
+}
+
+/**
+ * The release that ends a drag must not also open the row. Once a drag
+ * activates, dnd-kit stops that click's propagation at the document but
+ * leaves its default, so a link would still navigate natively. Where React
+ * listens below the document (Desktop mounts on `#root`), it never sees that
+ * click at all. A window capture listener runs first and cancels it.
+ *
+ * Call `arm` from `onDragStart` and `release` from `onDragEnd` and
+ * `onDragCancel`.
+ */
+export function useDragClickGuard() {
+ const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
+ const disarm = useCallback(() => {
+ if (timer.current) clearTimeout(timer.current);
+ timer.current = null;
+ window.removeEventListener("click", preventDefault, true);
+ }, []);
+ useEffect(() => disarm, [disarm]);
+ return {
+ arm: useCallback(() => {
+ disarm();
+ window.addEventListener("click", preventDefault, true);
+ }, [disarm]),
+ release: useCallback(() => {
+ timer.current = setTimeout(disarm, DRAG_CLICK_GUARD_MS);
+ }, [disarm]),
+ };
+}