Skip to content

Commit 66205ff

Browse files
committed
Subjective nits
1 parent 134ff10 commit 66205ff

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,10 @@ function updateListeners() {
327327
}
328328
});
329329
}
330-
ownerDocumentCounts.forEach((count, ownerDocument) => {
330+
331+
ownerDocumentCounts.forEach((_, ownerDocument) => {
331332
const { body } = ownerDocument;
333+
332334
body.addEventListener("pointerup", handlePointerUp, options);
333335
body.addEventListener("pointercancel", handlePointerUp, options);
334336
});

0 commit comments

Comments
 (0)