Skip to content

Commit ed4bccc

Browse files
authored
Add failing (disabled) e2e test (#689)
Resolves #688
1 parent 08cfd6f commit ed4bccc

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

integrations/tests/tests/pointer-interactions.spec.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,40 @@ test.describe("pointer interactions", () => {
535535
await expect(separator).toHaveAttribute("data-separator", "inactive");
536536
});
537537

538+
// See github.com/bvaughn/react-resizable-panels/issues/688
539+
test("should update separator state when the cursor is released while over an iframe", async ({
540+
page: mainPage
541+
}) => {
542+
const page = await goToUrl(
543+
mainPage,
544+
<Group className="gap-0!">
545+
<Panel className="p-0! *:p-0!" id="left" minSize="25%">
546+
<IFrame className="w-full h-full bg-red-300" />
547+
</Panel>
548+
<Separator id="separator" />
549+
<Panel className="p-0! *:p-0!" id="right" />
550+
</Group>
551+
);
552+
553+
const separator = page.getByTestId("separator");
554+
555+
const { x, y } = getCenterCoordinates((await separator.boundingBox())!);
556+
557+
await expect(separator).toHaveAttribute("data-separator", "inactive");
558+
559+
await page.mouse.move(x, y);
560+
await expect(separator).toHaveAttribute("data-separator", "hover");
561+
562+
await page.mouse.down();
563+
await expect(separator).toHaveAttribute("data-separator", "active");
564+
565+
await page.mouse.move(x - 25, y, { steps: 10 });
566+
await expect(separator).toHaveAttribute("data-separator", "active");
567+
568+
await page.mouse.up();
569+
await expect(separator).toHaveAttribute("data-separator", "inactive");
570+
});
571+
538572
test("should not prevent click events if no drag occurs", async ({
539573
page: mainPage
540574
}) => {

lib/global/event-handlers/onDocumentPointerDown.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export function onDocumentPointerDown(event: PointerEvent) {
2626
current.separator.element.focus({
2727
preventScroll: true
2828
});
29+
30+
// TRICKY
31+
// Calling setPointerCapture() here would help with detecting pointer "pointermove"/"pointerup" events that happen over iframes
32+
// but it would also prevent "click" events from firing if the use releases without actually dragging
33+
// Because of this, it's safer to wait until the first "pointermove" event to set capture
2934
}
3035
}
3136

lib/global/event-handlers/onDocumentPointerMove.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ export function onDocumentPointerMove(event: PointerEvent) {
4242
return;
4343
}
4444

45+
for (const hitRegion of interactionState.hitRegions) {
46+
if (hitRegion.separator) {
47+
const { element } = hitRegion.separator;
48+
if (!element.hasPointerCapture?.(event.pointerId)) {
49+
element.setPointerCapture?.(event.pointerId);
50+
}
51+
}
52+
}
53+
4554
updateActiveHitRegions({
4655
document: event.currentTarget as Document,
4756
event,

0 commit comments

Comments
 (0)