Skip to content

Commit 43cba81

Browse files
Attach handlePointerUp to ownerDocument body
1 parent 96a4c5b commit 43cba81

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

packages/react-resizable-panels/src/PanelResizeHandle.test.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,36 @@ describe("PanelResizeHandle", () => {
258258
});
259259
});
260260

261+
262+
describe("event handlers when rendered in a separate document", () => {
263+
let separateWindowDocument: Document;
264+
beforeEach(() => {
265+
// @ts-expect-error
266+
global.IS_REACT_ACT_ENVIRONMENT = true;
267+
268+
separateWindowDocument = document.implementation.createHTMLDocument();
269+
container = separateWindowDocument.createElement("div");
270+
separateWindowDocument.body.appendChild(container);
271+
jest.spyOn(separateWindowDocument.body,"addEventListener");
272+
jest.spyOn(document.body,"addEventListener");
273+
expectedWarnings = [];
274+
root = createRoot(container);
275+
});
276+
277+
it("should add the pointerup event to the separate document NOT the main document", () => {
278+
const { leftElement } = setupMockedGroup();
279+
280+
act(() => {
281+
dispatchPointerEvent("pointermove", leftElement);
282+
});
283+
284+
expect(separateWindowDocument.body.addEventListener).toHaveBeenCalledWith('pointerup');
285+
expect(document.body.addEventListener).not.toHaveBeenCalled();
286+
287+
});
288+
});
289+
290+
261291
describe("data attributes", () => {
262292
it("should initialize with the correct props based attributes", () => {
263293
const { leftElement, rightElement } = setupMockedGroup();

packages/react-resizable-panels/src/PanelResizeHandleRegistry.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,12 @@ function updateListeners() {
324324
body.addEventListener("contextmenu", handlePointerUp, options);
325325
body.addEventListener("pointerleave", handlePointerMove, options);
326326
body.addEventListener("pointermove", handlePointerMove, options);
327+
328+
body.addEventListener("pointerup", handlePointerUp, options);
329+
body.addEventListener("pointercancel", handlePointerUp, options);
327330
}
328331
});
329332
}
330-
331-
window.addEventListener("pointerup", handlePointerUp, options);
332-
window.addEventListener("pointercancel", handlePointerUp, options);
333333
} else {
334334
ownerDocumentCounts.forEach((count, ownerDocument) => {
335335
const { body } = ownerDocument;

0 commit comments

Comments
 (0)