Skip to content

Commit 134ff10

Browse files
ImmanuelBaskaranbvaughn
authored andcommitted
Attach handlePointerUp to ownerDocument body
1 parent 84df208 commit 134ff10

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,37 @@ describe("PanelResizeHandle", () => {
259259
});
260260
});
261261

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

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,11 @@ function updateListeners() {
327327
}
328328
});
329329
}
330-
331-
window.addEventListener("pointerup", handlePointerUp, options);
332-
window.addEventListener("pointercancel", handlePointerUp, options);
330+
ownerDocumentCounts.forEach((count, ownerDocument) => {
331+
const { body } = ownerDocument;
332+
body.addEventListener("pointerup", handlePointerUp, options);
333+
body.addEventListener("pointercancel", handlePointerUp, options);
334+
});
333335
} else {
334336
ownerDocumentCounts.forEach((count, ownerDocument) => {
335337
const { body } = ownerDocument;

0 commit comments

Comments
 (0)