From 88abb16245e976a035bcea49188eb25747363ae1 Mon Sep 17 00:00:00 2001 From: Bashar Date: Mon, 28 Sep 2026 03:17:08 +0300 Subject: [PATCH 1/2] test(vanilla): cover release over video controls --- packages/vanilla/tests/interaction.spec.ts | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/packages/vanilla/tests/interaction.spec.ts b/packages/vanilla/tests/interaction.spec.ts index 295f7f9..c954a70 100644 --- a/packages/vanilla/tests/interaction.spec.ts +++ b/packages/vanilla/tests/interaction.spec.ts @@ -4,6 +4,7 @@ type TestWindow = Window & { events?: string[]; started?: boolean; beforeDrag?: number; + stopped?: boolean; }; test('emits the drag lifecycle and maintains the selected elements', async ({ selection }) => { @@ -26,6 +27,53 @@ test('emits the drag lifecycle and maintains the selected elements', async ({ se expect(await selection.isAreaMounted()).toBe(false); }); +test('stops a drag released over native video controls', async ({ page, selection }) => { + await selection.setup(); + await selection.run((instance) => { + const browserWindow = window as TestWindow; + browserWindow.stopped = false; + instance.on('stop', () => { + browserWindow.stopped = true; + }); + }); + + await page.evaluate(() => { + const video = document.createElement('video'); + video.id = 'native-video-controls'; + video.controls = true; + Object.assign(video.style, { + position: 'fixed', + left: '320px', + top: '32px', + width: '320px', + height: '180px', + background: 'black' + }); + document.body.append(video); + }); + + const nativeVideo = page.locator('#native-video-controls'); + await expect(nativeVideo).toBeVisible(); + expect(await nativeVideo.evaluate((element) => (element as HTMLVideoElement).controls)).toBe(true); + + const start = await selection.items.first().boundingBox(); + const video = await nativeVideo.boundingBox(); + + if (!start || !video) throw new Error('Could not measure drag targets'); + + await page.mouse.move(start.x + 10, start.y + 10); + await page.mouse.down(); + await page.mouse.move(start.x + 40, start.y + 40, { steps: 10 }); + + await expect.poll(() => selection.isAreaMounted()).toBe(true); + + await page.mouse.move(video.x + video.width / 2, video.y + video.height - 8, { steps: 20 }); + await page.mouse.up(); + + expect(await selection.run(() => (window as TestWindow).stopped)).toBe(true); + expect(await selection.isAreaMounted()).toBe(false); +}); + test('allows beforestart and beforedrag handlers to cancel interaction', async ({ selection }) => { await selection.setup(); await selection.run((instance) => instance.on('beforestart', () => false)); From 1f5f346f49f2a06736da6c23651c3cdd22040f38 Mon Sep 17 00:00:00 2001 From: Bashar Date: Mon, 28 Sep 2026 03:17:18 +0300 Subject: [PATCH 2/2] fix(vanilla): preserve drag release over native controls --- packages/vanilla/src/index.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/vanilla/src/index.ts b/packages/vanilla/src/index.ts index f5428c6..a6daebe 100644 --- a/packages/vanilla/src/index.ts +++ b/packages/vanilla/src/index.ts @@ -60,6 +60,8 @@ export default class SelectionArea extends EventTarget { // If a single click is being performed, it's a single-click until the user dragged the mouse private _singleClick = true; private _frame: Frames; + private _pointer?: { id: number; button: number; x: number; y: number }; + private _activePointerId?: number; // Required data for scrolling private _scrollAvailable = true; @@ -160,6 +162,7 @@ export default class SelectionArea extends EventTarget { const { document, features } = this._options; const fn = activate ? on : off; + fn(document, 'pointerdown', this._onPointerStart); fn(document, 'mousedown', this._onTapStart); if (features.touch) { @@ -167,8 +170,23 @@ export default class SelectionArea extends EventTarget { } } + _onPointerStart(evt: PointerEvent): void { + this._pointer = + evt.pointerType === 'mouse' + ? { id: evt.pointerId, button: evt.button, x: evt.clientX, y: evt.clientY } + : undefined; + } + _onTapStart(evt: MouseEvent | TouchEvent, silent = false): void { const { x, y, target } = simplifyEvent(evt); + const pointer = + evt instanceof MouseEvent && + this._pointer?.button === evt.button && + this._pointer.x === evt.clientX && + this._pointer.y === evt.clientY + ? this._pointer + : undefined; + this._pointer = undefined; const { document, startAreas, boundaries, features, behaviour } = this._options; const targetBoundingClientRect = target.getBoundingClientRect(); @@ -198,6 +216,7 @@ export default class SelectionArea extends EventTarget { return; } + this._activePointerId = pointer?.id; this._areaLocation = { x1: x, y1: y, x2: 0, y2: 0 }; // Lock scrolling in the target container @@ -315,10 +334,15 @@ export default class SelectionArea extends EventTarget { off(document, ['mousemove', 'touchmove'], this._delayedTapMove, { passive: false }); if (this._emitEvent('beforedrag', evt) === false) { + this._activePointerId = undefined; off(document, ['mouseup', 'touchcancel', 'touchend'], this._onTapStop); return; } + if (this._activePointerId !== undefined) { + this._targetElement!.setPointerCapture(this._activePointerId); + } + on(document, ['mousemove', 'touchmove'], this._onTapMove, { passive: false }); // Make area element visible @@ -610,6 +634,11 @@ export default class SelectionArea extends EventTarget { const { document, features } = this._options; const { _singleClick } = this; + if (this._activePointerId !== undefined && this._targetElement?.hasPointerCapture(this._activePointerId)) { + this._targetElement.releasePointerCapture(this._activePointerId); + } + this._activePointerId = undefined; + // Remove event handlers off(this._targetElement, 'scroll', this._onStartAreaScroll); off(document, ['mousemove', 'touchmove'], this._delayedTapMove);