Skip to content

Build your personal knowledge base with Trilium Notes

client: fix an issue

Adorian Dorand0acf0692309
diff --git a/apps/client/src/widgets/react/ScrollableLabel.spec.tsx b/apps/client/src/widgets/react/ScrollableLabel.spec.tsx
index 11c078f0f9..84112876f5 100644
--- a/apps/client/src/widgets/react/ScrollableLabel.spec.tsx
+++ b/apps/client/src/widgets/react/ScrollableLabel.spec.tsx
@@ -52,10 +52,10 @@ async function scrollTo(label: HTMLDivElement, scrollLeft: number) {
await act(async () => { await new Promise((resolve) => setTimeout(resolve, 0)); });
}
-/** Dispatches a pointer event of the primary mouse button at `clientX`. */
+/** Dispatches a pointer event of the primary mouse button, held down, at `clientX`. */
function pointer(target: Element, type: string, clientX: number, init: PointerEventInit = {}) {
target.dispatchEvent(new PointerEvent(type, {
- bubbles: true, pointerId: 1, pointerType: "mouse", button: 0, clientX, ...init
+ bubbles: true, pointerId: 1, pointerType: "mouse", button: 0, buttons: 1, clientX, ...init
}));
}
@@ -226,6 +226,15 @@ describe("ScrollableLabel", () => {
expect(label.scrollLeft).toBe(100);
});
+ it("forgets a press released away from it before it dragged", () => {
+ const label = renderLabel("a name longer than its box", 300);
+
+ pointer(label, "pointerdown", 100);
+ pointer(label, "pointermove", 40, { buttons: 0 });
+ expect(label.scrollLeft).toBe(0);
+ expect(isPrevented(label, "dragstart")).toBe(false);
+ });
+
it("leaves the presses of a touch, another button, or on a label that fits alone", () => {
const presses: [ number, PointerEventInit ][] = [
[ 300, { pointerType: "touch" } ],
diff --git a/apps/client/src/widgets/react/ScrollableLabel.tsx b/apps/client/src/widgets/react/ScrollableLabel.tsx
index c57a6e5d02..90805bd8d0 100644
--- a/apps/client/src/widgets/react/ScrollableLabel.tsx
+++ b/apps/client/src/widgets/react/ScrollableLabel.tsx
@@ -149,6 +149,11 @@ function useMouseDragScroll(ref: RefObject<HTMLElement | null>) {
};
const onPointerMove = (event: PointerEvent) => {
if (event.pointerId !== press?.pointerId) return;
+ // Released away from the label before the drag captured the pointer.
+ if (!(event.buttons & 1)) {
+ press = undefined;
+ return;
+ }
const distance = event.clientX - press.x;
if (!press.isDragging && Math.abs(distance) >= DRAG_THRESHOLD) {