From 7a8c7ca61d2d579447f9b0401088ce346a935d6e Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Thu, 10 Apr 2025 02:57:39 +0530 Subject: [PATCH] fix: background things get selected on Safari even while dragging --- src/draggable.attempts/6/Draggable.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/draggable.attempts/6/Draggable.ts b/src/draggable.attempts/6/Draggable.ts index 0d6268d..37044d9 100644 --- a/src/draggable.attempts/6/Draggable.ts +++ b/src/draggable.attempts/6/Draggable.ts @@ -101,6 +101,9 @@ export function makeDraggable(card: HTMLElement, opts: DraggableOpts = {}) { lastMousePosition = { x: e.pageX, y: e.pageY }; angularVelocity = 0; + + document.body.style.userSelect = "none"; + document.body.style.webkitUserSelect = "none"; }; const move = (e: PointerEvent) => { @@ -151,6 +154,8 @@ export function makeDraggable(card: HTMLElement, opts: DraggableOpts = {}) { state.dragging = false; activePointerId = null; card.style.cursor = "grab"; + document.body.style.userSelect = "auto"; + document.body.style.webkitUserSelect = "auto"; // Momentum is handled in the render loop }; @@ -239,7 +244,6 @@ export function makeDraggable(card: HTMLElement, opts: DraggableOpts = {}) { card.style.cursor = "grab"; card.style.touchAction = "none"; - card.style.userSelect = "none"; card.style.transform = `translate(0px, 0px) rotate(${rotation}rad)`;