Skip to content

Commit 8e032de

Browse files
committed
Subjective nits
1 parent 134ff10 commit 8e032de

2 files changed

Lines changed: 25 additions & 15 deletions

File tree

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ describe("PanelResizeHandle", () => {
3131
beforeEach(() => {
3232
// @ts-expect-error
3333
global.IS_REACT_ACT_ENVIRONMENT = true;
34+
3435
container = document.createElement("div");
3536
document.body.appendChild(container);
3637

@@ -259,37 +260,42 @@ describe("PanelResizeHandle", () => {
259260
});
260261
});
261262

263+
describe("portals and child windows", () => {
264+
test("should add the pointerup event to the separate document NOT the main document", () => {
265+
act(() => {
266+
root.unmount();
267+
});
262268

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;
269+
const separateWindowDocument =
270+
document.implementation.createHTMLDocument();
268271

269-
separateWindowDocument = document.implementation.createHTMLDocument();
270272
container = separateWindowDocument.createElement("div");
273+
271274
separateWindowDocument.body.appendChild(container);
272-
jest.spyOn(separateWindowDocument.body,"addEventListener");
273-
jest.spyOn(document.body,"addEventListener");
275+
276+
vi.spyOn(separateWindowDocument.body, "addEventListener");
277+
vi.spyOn(document.body, "addEventListener");
278+
274279
expectedWarnings = [];
280+
275281
root = createRoot(container);
276-
});
277282

278-
it("should add the pointerup event to the separate document NOT the main document", () => {
279283
const { leftElement } = setupMockedGroup();
280284

281285
act(() => {
282286
dispatchPointerEvent("pointerdown", leftElement);
283287
dispatchPointerEvent("pointerup", leftElement);
284288
});
285289

286-
expect(separateWindowDocument.body.addEventListener).toHaveBeenCalledWith("pointerup", expect.anything(), expect.anything());
290+
expect(separateWindowDocument.body.addEventListener).toHaveBeenCalledWith(
291+
"pointerup",
292+
expect.anything(),
293+
expect.anything()
294+
);
287295
expect(document.body.addEventListener).not.toHaveBeenCalled();
288-
289296
});
290297
});
291298

292-
293299
describe("data attributes", () => {
294300
test("should initialize with the correct props based attributes", () => {
295301
const { leftElement, rightElement } = setupMockedGroup();

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,14 @@ function updateListeners() {
327327
}
328328
});
329329
}
330+
330331
ownerDocumentCounts.forEach((count, ownerDocument) => {
331332
const { body } = ownerDocument;
332-
body.addEventListener("pointerup", handlePointerUp, options);
333-
body.addEventListener("pointercancel", handlePointerUp, options);
333+
334+
if (count > 0) {
335+
body.addEventListener("pointerup", handlePointerUp, options);
336+
body.addEventListener("pointercancel", handlePointerUp, options);
337+
}
334338
});
335339
} else {
336340
ownerDocumentCounts.forEach((count, ownerDocument) => {

0 commit comments

Comments
 (0)