diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index 9cfe57c43e..41ce12eceb 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -600,13 +600,20 @@ const MAX_WIDTH = 480; let isResizing = false; + let activePointerId: number | null = null; + let activeResizer: HTMLElement | null = null; let startWidth = 0; let startClientX = 0; - const resizeStartHandler = (e: MouseEvent) => { + const resizeStartHandler = (e: PointerEvent) => { if ($mobile) return; + + e.preventDefault(); isResizing = true; + activePointerId = e.pointerId; + activeResizer = e.currentTarget as HTMLElement; + activeResizer.setPointerCapture?.(e.pointerId); startClientX = e.clientX; startWidth = $sidebarWidth ?? 245; @@ -614,15 +621,23 @@ document.body.style.userSelect = 'none'; }; - const resizeEndHandler = () => { + const resizeEndHandler = (e?: PointerEvent) => { if (!isResizing) return; + if (e && activePointerId !== null && e.pointerId !== activePointerId) return; + isResizing = false; + if (activePointerId !== null && activeResizer?.hasPointerCapture?.(activePointerId)) { + activeResizer.releasePointerCapture(activePointerId); + } + activePointerId = null; + activeResizer = null; + document.body.style.userSelect = ''; localStorage.setItem('sidebarWidth', String($sidebarWidth)); }; - const resizeSidebarHandler = (endClientX) => { + const resizeSidebarHandler = (endClientX: number) => { const dx = endClientX - startClientX; const newSidebarWidth = Math.min(MAX_WIDTH, Math.max(MIN_WIDTH, startWidth + dx)); @@ -630,6 +645,12 @@ document.documentElement.style.setProperty('--sidebar-width', `${newSidebarWidth}px`); }; + onDestroy(() => { + if (isResizing) { + document.body.style.userSelect = ''; + } + }); + onMount(async () => { try { const width = Number(localStorage.getItem('sidebarWidth')); @@ -861,13 +882,13 @@ /> { + on:pointermove={(e) => { if (!isResizing) return; + if (activePointerId !== null && e.pointerId !== activePointerId) return; resizeSidebarHandler(e.clientX); }} - on:mouseup={() => { - resizeEndHandler(); - }} + on:pointerup={resizeEndHandler} + on:pointercancel={resizeEndHandler} />
+ style="touch-action: none;" + >
{/if} {/if}