react-resizable-panels 2.1.5 → 2.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/declarations/src/PanelGroup.d.ts +2 -0
- package/dist/react-resizable-panels.browser.cjs.js +16 -10
- package/dist/react-resizable-panels.browser.development.cjs.js +16 -10
- package/dist/react-resizable-panels.browser.development.esm.js +16 -10
- package/dist/react-resizable-panels.browser.esm.js +16 -10
- package/dist/react-resizable-panels.cjs.js +16 -10
- package/dist/react-resizable-panels.development.cjs.js +16 -10
- package/dist/react-resizable-panels.development.esm.js +16 -10
- package/dist/react-resizable-panels.development.node.cjs.js +16 -10
- package/dist/react-resizable-panels.development.node.esm.js +16 -10
- package/dist/react-resizable-panels.esm.js +16 -10
- package/dist/react-resizable-panels.node.cjs.js +16 -10
- package/dist/react-resizable-panels.node.esm.js +16 -10
- package/package.json +7 -1
- package/.eslintrc.cjs +0 -27
- package/CHANGELOG.md +0 -569
- package/jest.config.js +0 -10
- package/react-resizable-panels-2.1.5.tgz +0 -0
- package/src/Panel.test.tsx +0 -1084
- package/src/Panel.ts +0 -259
- package/src/PanelGroup.test.tsx +0 -443
- package/src/PanelGroup.ts +0 -985
- package/src/PanelGroupContext.ts +0 -42
- package/src/PanelResizeHandle.test.tsx +0 -367
- package/src/PanelResizeHandle.ts +0 -246
- package/src/PanelResizeHandleRegistry.ts +0 -336
- package/src/constants.ts +0 -1
- package/src/env-conditions/browser.ts +0 -1
- package/src/env-conditions/development.ts +0 -1
- package/src/env-conditions/node.ts +0 -1
- package/src/env-conditions/production.ts +0 -1
- package/src/env-conditions/unknown.ts +0 -1
- package/src/hooks/useForceUpdate.ts +0 -7
- package/src/hooks/useIsomorphicEffect.ts +0 -8
- package/src/hooks/useUniqueId.ts +0 -19
- package/src/hooks/useWindowSplitterBehavior.ts +0 -90
- package/src/hooks/useWindowSplitterPanelGroupBehavior.ts +0 -201
- package/src/index.ts +0 -77
- package/src/types.ts +0 -5
- package/src/utils/adjustLayoutByDelta.test.ts +0 -2061
- package/src/utils/adjustLayoutByDelta.ts +0 -308
- package/src/utils/arrays.ts +0 -13
- package/src/utils/assert.ts +0 -10
- package/src/utils/calculateAriaValues.test.ts +0 -106
- package/src/utils/calculateAriaValues.ts +0 -45
- package/src/utils/calculateDeltaPercentage.ts +0 -63
- package/src/utils/calculateDragOffsetPercentage.ts +0 -40
- package/src/utils/calculateUnsafeDefaultLayout.test.ts +0 -87
- package/src/utils/calculateUnsafeDefaultLayout.ts +0 -50
- package/src/utils/callPanelCallbacks.ts +0 -49
- package/src/utils/compareLayouts.test.ts +0 -9
- package/src/utils/compareLayouts.ts +0 -12
- package/src/utils/computePanelFlexBoxStyle.test.ts +0 -123
- package/src/utils/computePanelFlexBoxStyle.ts +0 -50
- package/src/utils/csp.ts +0 -9
- package/src/utils/cursor.ts +0 -103
- package/src/utils/debounce.ts +0 -18
- package/src/utils/determinePivotIndices.ts +0 -15
- package/src/utils/dom/getPanelElement.ts +0 -10
- package/src/utils/dom/getPanelElementsForGroup.ts +0 -8
- package/src/utils/dom/getPanelGroupElement.ts +0 -21
- package/src/utils/dom/getResizeHandleElement.ts +0 -10
- package/src/utils/dom/getResizeHandleElementIndex.ts +0 -13
- package/src/utils/dom/getResizeHandleElementsForGroup.ts +0 -10
- package/src/utils/dom/getResizeHandlePanelIds.ts +0 -19
- package/src/utils/events/getResizeEventCoordinates.ts +0 -23
- package/src/utils/events/getResizeEventCursorPosition.ts +0 -14
- package/src/utils/events/index.ts +0 -13
- package/src/utils/getInputType.ts +0 -5
- package/src/utils/initializeDefaultStorage.ts +0 -26
- package/src/utils/numbers/fuzzyCompareNumbers.test.ts +0 -16
- package/src/utils/numbers/fuzzyCompareNumbers.ts +0 -21
- package/src/utils/numbers/fuzzyLayoutsEqual.ts +0 -22
- package/src/utils/numbers/fuzzyNumbersEqual.ts +0 -9
- package/src/utils/rects/getIntersectingRectangle.test.ts +0 -198
- package/src/utils/rects/getIntersectingRectangle.ts +0 -28
- package/src/utils/rects/intersects.test.ts +0 -197
- package/src/utils/rects/intersects.ts +0 -23
- package/src/utils/rects/types.ts +0 -6
- package/src/utils/resizePanel.test.ts +0 -59
- package/src/utils/resizePanel.ts +0 -47
- package/src/utils/serialization.ts +0 -87
- package/src/utils/test-utils.ts +0 -205
- package/src/utils/validatePanelConstraints.test.ts +0 -143
- package/src/utils/validatePanelConstraints.ts +0 -69
- package/src/utils/validatePanelGroupLayout.test.ts +0 -148
- package/src/utils/validatePanelGroupLayout.ts +0 -95
- package/src/vendor/react.ts +0 -73
- package/src/vendor/stacking-order.ts +0 -139
package/src/Panel.test.tsx
DELETED
|
@@ -1,1084 +0,0 @@
|
|
|
1
|
-
import { Root, createRoot } from "react-dom/client";
|
|
2
|
-
import { act } from "react-dom/test-utils";
|
|
3
|
-
import { ImperativePanelHandle, Panel, PanelGroup, PanelResizeHandle } from ".";
|
|
4
|
-
import { assert } from "./utils/assert";
|
|
5
|
-
import { getPanelElement } from "./utils/dom/getPanelElement";
|
|
6
|
-
import {
|
|
7
|
-
mockPanelGroupOffsetWidthAndHeight,
|
|
8
|
-
verifyAttribute,
|
|
9
|
-
verifyExpandedPanelGroupLayout,
|
|
10
|
-
} from "./utils/test-utils";
|
|
11
|
-
import { createRef } from "./vendor/react";
|
|
12
|
-
|
|
13
|
-
describe("PanelGroup", () => {
|
|
14
|
-
let expectedWarnings: string[] = [];
|
|
15
|
-
let root: Root;
|
|
16
|
-
let container: HTMLElement;
|
|
17
|
-
let uninstallMockOffsetWidthAndHeight: () => void;
|
|
18
|
-
|
|
19
|
-
function expectWarning(expectedMessage: string) {
|
|
20
|
-
expectedWarnings.push(expectedMessage);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
// @ts-expect-error
|
|
25
|
-
global.IS_REACT_ACT_ENVIRONMENT = true;
|
|
26
|
-
|
|
27
|
-
uninstallMockOffsetWidthAndHeight = mockPanelGroupOffsetWidthAndHeight();
|
|
28
|
-
|
|
29
|
-
container = document.createElement("div");
|
|
30
|
-
document.body.appendChild(container);
|
|
31
|
-
|
|
32
|
-
expectedWarnings = [];
|
|
33
|
-
root = createRoot(container);
|
|
34
|
-
|
|
35
|
-
jest.spyOn(console, "warn").mockImplementation((actualMessage: string) => {
|
|
36
|
-
const match = expectedWarnings.findIndex((expectedMessage) => {
|
|
37
|
-
return actualMessage.includes(expectedMessage);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
if (match >= 0) {
|
|
41
|
-
expectedWarnings.splice(match, 1);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
throw Error(`Unexpected warning: ${actualMessage}`);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
afterEach(() => {
|
|
50
|
-
uninstallMockOffsetWidthAndHeight();
|
|
51
|
-
|
|
52
|
-
jest.clearAllMocks();
|
|
53
|
-
jest.resetModules();
|
|
54
|
-
|
|
55
|
-
act(() => {
|
|
56
|
-
root.unmount();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
expect(expectedWarnings).toHaveLength(0);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe("imperative handle API", () => {
|
|
63
|
-
describe("collapse and expand", () => {
|
|
64
|
-
let leftPanelRef = createRef<ImperativePanelHandle>();
|
|
65
|
-
let rightPanelRef = createRef<ImperativePanelHandle>();
|
|
66
|
-
|
|
67
|
-
let mostRecentLayout: number[] | null;
|
|
68
|
-
|
|
69
|
-
beforeEach(() => {
|
|
70
|
-
leftPanelRef = createRef<ImperativePanelHandle>();
|
|
71
|
-
rightPanelRef = createRef<ImperativePanelHandle>();
|
|
72
|
-
|
|
73
|
-
mostRecentLayout = null;
|
|
74
|
-
|
|
75
|
-
const onLayout = (layout: number[]) => {
|
|
76
|
-
mostRecentLayout = layout;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
act(() => {
|
|
80
|
-
root.render(
|
|
81
|
-
<PanelGroup direction="horizontal" onLayout={onLayout}>
|
|
82
|
-
<Panel collapsible defaultSize={50} ref={leftPanelRef} />
|
|
83
|
-
<PanelResizeHandle />
|
|
84
|
-
<Panel collapsible defaultSize={50} ref={rightPanelRef} />
|
|
85
|
-
</PanelGroup>
|
|
86
|
-
);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("should expand and collapse the first panel in a group", () => {
|
|
91
|
-
assert(mostRecentLayout, "");
|
|
92
|
-
|
|
93
|
-
verifyExpandedPanelGroupLayout(mostRecentLayout, [50, 50]);
|
|
94
|
-
expect(leftPanelRef.current?.isCollapsed()).toBe(false);
|
|
95
|
-
expect(rightPanelRef.current?.isCollapsed()).toBe(false);
|
|
96
|
-
act(() => {
|
|
97
|
-
leftPanelRef.current?.collapse();
|
|
98
|
-
});
|
|
99
|
-
expect(leftPanelRef.current?.isCollapsed()).toBe(true);
|
|
100
|
-
expect(rightPanelRef.current?.isCollapsed()).toBe(false);
|
|
101
|
-
verifyExpandedPanelGroupLayout(mostRecentLayout, [0, 100]);
|
|
102
|
-
act(() => {
|
|
103
|
-
leftPanelRef.current?.expand();
|
|
104
|
-
});
|
|
105
|
-
expect(leftPanelRef.current?.isCollapsed()).toBe(false);
|
|
106
|
-
expect(rightPanelRef.current?.isCollapsed()).toBe(false);
|
|
107
|
-
verifyExpandedPanelGroupLayout(mostRecentLayout, [50, 50]);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it("should expand and collapse the last panel in a group", () => {
|
|
111
|
-
assert(mostRecentLayout, "");
|
|
112
|
-
|
|
113
|
-
verifyExpandedPanelGroupLayout(mostRecentLayout, [50, 50]);
|
|
114
|
-
expect(leftPanelRef.current?.isCollapsed()).toBe(false);
|
|
115
|
-
expect(rightPanelRef.current?.isCollapsed()).toBe(false);
|
|
116
|
-
act(() => {
|
|
117
|
-
rightPanelRef.current?.collapse();
|
|
118
|
-
});
|
|
119
|
-
verifyExpandedPanelGroupLayout(mostRecentLayout, [100, 0]);
|
|
120
|
-
expect(leftPanelRef.current?.isCollapsed()).toBe(false);
|
|
121
|
-
expect(rightPanelRef.current?.isCollapsed()).toBe(true);
|
|
122
|
-
act(() => {
|
|
123
|
-
rightPanelRef.current?.expand();
|
|
124
|
-
});
|
|
125
|
-
verifyExpandedPanelGroupLayout(mostRecentLayout, [50, 50]);
|
|
126
|
-
expect(leftPanelRef.current?.isCollapsed()).toBe(false);
|
|
127
|
-
expect(rightPanelRef.current?.isCollapsed()).toBe(false);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it("should re-expand to the most recent size before collapsing", () => {
|
|
131
|
-
assert(mostRecentLayout, "");
|
|
132
|
-
|
|
133
|
-
verifyExpandedPanelGroupLayout(mostRecentLayout, [50, 50]);
|
|
134
|
-
act(() => {
|
|
135
|
-
leftPanelRef.current?.resize(30);
|
|
136
|
-
});
|
|
137
|
-
verifyExpandedPanelGroupLayout(mostRecentLayout, [30, 70]);
|
|
138
|
-
act(() => {
|
|
139
|
-
leftPanelRef.current?.collapse();
|
|
140
|
-
});
|
|
141
|
-
verifyExpandedPanelGroupLayout(mostRecentLayout, [0, 100]);
|
|
142
|
-
act(() => {
|
|
143
|
-
leftPanelRef.current?.expand();
|
|
144
|
-
});
|
|
145
|
-
verifyExpandedPanelGroupLayout(mostRecentLayout, [30, 70]);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it("should report the correct state with collapsedSizes that have many decimal places", () => {
|
|
149
|
-
act(() => {
|
|
150
|
-
root.render(
|
|
151
|
-
<PanelGroup direction="horizontal">
|
|
152
|
-
<Panel
|
|
153
|
-
collapsedSize={3.8764385221078133}
|
|
154
|
-
collapsible
|
|
155
|
-
defaultSize={50}
|
|
156
|
-
minSize={15}
|
|
157
|
-
ref={leftPanelRef}
|
|
158
|
-
/>
|
|
159
|
-
<PanelResizeHandle />
|
|
160
|
-
<Panel collapsible defaultSize={50} ref={rightPanelRef} />
|
|
161
|
-
</PanelGroup>
|
|
162
|
-
);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
act(() => {
|
|
166
|
-
leftPanelRef.current?.collapse();
|
|
167
|
-
});
|
|
168
|
-
expect(leftPanelRef.current?.isCollapsed()).toBe(true);
|
|
169
|
-
expect(leftPanelRef.current?.isExpanded()).toBe(false);
|
|
170
|
-
|
|
171
|
-
act(() => {
|
|
172
|
-
root.render(
|
|
173
|
-
<PanelGroup direction="horizontal">
|
|
174
|
-
<Panel
|
|
175
|
-
collapsedSize={3.8764385221078132}
|
|
176
|
-
collapsible
|
|
177
|
-
defaultSize={50}
|
|
178
|
-
minSize={15}
|
|
179
|
-
ref={leftPanelRef}
|
|
180
|
-
/>
|
|
181
|
-
<PanelResizeHandle />
|
|
182
|
-
<Panel collapsible defaultSize={50} ref={rightPanelRef} />
|
|
183
|
-
</PanelGroup>
|
|
184
|
-
);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
expect(leftPanelRef.current?.isCollapsed()).toBe(true);
|
|
188
|
-
expect(leftPanelRef.current?.isExpanded()).toBe(false);
|
|
189
|
-
|
|
190
|
-
act(() => {
|
|
191
|
-
leftPanelRef.current?.expand();
|
|
192
|
-
});
|
|
193
|
-
expect(leftPanelRef.current?.isCollapsed()).toBe(false);
|
|
194
|
-
expect(leftPanelRef.current?.isExpanded()).toBe(true);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
describe("when a panel is mounted in a collapsed state", () => {
|
|
198
|
-
beforeEach(() => {
|
|
199
|
-
act(() => {
|
|
200
|
-
root.unmount();
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it("should expand to the panel's minSize", () => {
|
|
205
|
-
const panelRef = createRef<ImperativePanelHandle>();
|
|
206
|
-
|
|
207
|
-
root = createRoot(container);
|
|
208
|
-
|
|
209
|
-
function renderPanelGroup() {
|
|
210
|
-
act(() => {
|
|
211
|
-
root.render(
|
|
212
|
-
<PanelGroup direction="horizontal">
|
|
213
|
-
<Panel
|
|
214
|
-
collapsible
|
|
215
|
-
defaultSize={0}
|
|
216
|
-
minSize={5}
|
|
217
|
-
ref={panelRef}
|
|
218
|
-
/>
|
|
219
|
-
<PanelResizeHandle />
|
|
220
|
-
<Panel />
|
|
221
|
-
</PanelGroup>
|
|
222
|
-
);
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// Re-render and confirmed collapsed by default
|
|
227
|
-
renderPanelGroup();
|
|
228
|
-
act(() => {
|
|
229
|
-
panelRef.current?.collapse();
|
|
230
|
-
});
|
|
231
|
-
expect(panelRef.current?.getSize()).toEqual(0);
|
|
232
|
-
|
|
233
|
-
// Toggling a panel should expand to the minSize (since there's no previous size to restore to)
|
|
234
|
-
act(() => {
|
|
235
|
-
panelRef.current?.expand();
|
|
236
|
-
});
|
|
237
|
-
expect(panelRef.current?.getSize()).toEqual(5);
|
|
238
|
-
|
|
239
|
-
// Collapse again
|
|
240
|
-
act(() => {
|
|
241
|
-
panelRef.current?.collapse();
|
|
242
|
-
});
|
|
243
|
-
expect(panelRef.current?.getSize()).toEqual(0);
|
|
244
|
-
|
|
245
|
-
// Toggling the panel should expand to the minSize override if one is specified
|
|
246
|
-
// Note this only works because the previous non-collapsed size is less than the minSize override
|
|
247
|
-
act(() => {
|
|
248
|
-
panelRef.current?.expand(15);
|
|
249
|
-
});
|
|
250
|
-
expect(panelRef.current?.getSize()).toEqual(15);
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
it("should support the (optional) default size", () => {
|
|
254
|
-
const panelRef = createRef<ImperativePanelHandle>();
|
|
255
|
-
|
|
256
|
-
root = createRoot(container);
|
|
257
|
-
|
|
258
|
-
function renderPanelGroup() {
|
|
259
|
-
act(() => {
|
|
260
|
-
root.render(
|
|
261
|
-
<PanelGroup autoSaveId="test" direction="horizontal">
|
|
262
|
-
<Panel
|
|
263
|
-
collapsible
|
|
264
|
-
defaultSize={0}
|
|
265
|
-
minSize={0}
|
|
266
|
-
ref={panelRef}
|
|
267
|
-
/>
|
|
268
|
-
<PanelResizeHandle />
|
|
269
|
-
<Panel />
|
|
270
|
-
</PanelGroup>
|
|
271
|
-
);
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// Re-render and confirmed collapsed by default
|
|
276
|
-
renderPanelGroup();
|
|
277
|
-
act(() => {
|
|
278
|
-
panelRef.current?.collapse();
|
|
279
|
-
});
|
|
280
|
-
expect(panelRef.current?.getSize()).toEqual(0);
|
|
281
|
-
|
|
282
|
-
// In this case, toggling the panel to expanded will not change its size
|
|
283
|
-
act(() => {
|
|
284
|
-
panelRef.current?.expand();
|
|
285
|
-
});
|
|
286
|
-
expect(panelRef.current?.getSize()).toEqual(0);
|
|
287
|
-
|
|
288
|
-
// But we can override the toggle behavior by passing an explicit min size
|
|
289
|
-
act(() => {
|
|
290
|
-
panelRef.current?.expand(10);
|
|
291
|
-
});
|
|
292
|
-
expect(panelRef.current?.getSize()).toEqual(10);
|
|
293
|
-
|
|
294
|
-
// Toggling an already-expanded panel should not do anything even if we pass a default size
|
|
295
|
-
act(() => {
|
|
296
|
-
panelRef.current?.expand(15);
|
|
297
|
-
});
|
|
298
|
-
expect(panelRef.current?.getSize()).toEqual(10);
|
|
299
|
-
});
|
|
300
|
-
});
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
describe("resize", () => {
|
|
304
|
-
let leftPanelRef = createRef<ImperativePanelHandle>();
|
|
305
|
-
let middlePanelRef = createRef<ImperativePanelHandle>();
|
|
306
|
-
let rightPanelRef = createRef<ImperativePanelHandle>();
|
|
307
|
-
|
|
308
|
-
let mostRecentLayout: number[] | null;
|
|
309
|
-
|
|
310
|
-
beforeEach(() => {
|
|
311
|
-
leftPanelRef = createRef<ImperativePanelHandle>();
|
|
312
|
-
middlePanelRef = createRef<ImperativePanelHandle>();
|
|
313
|
-
rightPanelRef = createRef<ImperativePanelHandle>();
|
|
314
|
-
|
|
315
|
-
mostRecentLayout = null;
|
|
316
|
-
|
|
317
|
-
const onLayout = (layout: number[]) => {
|
|
318
|
-
mostRecentLayout = layout;
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
act(() => {
|
|
322
|
-
root.render(
|
|
323
|
-
<PanelGroup direction="horizontal" onLayout={onLayout}>
|
|
324
|
-
<Panel defaultSize={20} ref={leftPanelRef} />
|
|
325
|
-
<PanelResizeHandle />
|
|
326
|
-
<Panel defaultSize={60} ref={middlePanelRef} />
|
|
327
|
-
<PanelResizeHandle />
|
|
328
|
-
<Panel defaultSize={20} ref={rightPanelRef} />
|
|
329
|
-
</PanelGroup>
|
|
330
|
-
);
|
|
331
|
-
});
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
it("should resize the first panel in a group", () => {
|
|
335
|
-
assert(mostRecentLayout, "");
|
|
336
|
-
|
|
337
|
-
verifyExpandedPanelGroupLayout(mostRecentLayout, [20, 60, 20]);
|
|
338
|
-
act(() => {
|
|
339
|
-
leftPanelRef.current?.resize(40);
|
|
340
|
-
});
|
|
341
|
-
verifyExpandedPanelGroupLayout(mostRecentLayout, [40, 40, 20]);
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
it("should resize the middle panel in a group", () => {
|
|
345
|
-
assert(mostRecentLayout, "");
|
|
346
|
-
|
|
347
|
-
verifyExpandedPanelGroupLayout(mostRecentLayout, [20, 60, 20]);
|
|
348
|
-
act(() => {
|
|
349
|
-
middlePanelRef.current?.resize(40);
|
|
350
|
-
});
|
|
351
|
-
verifyExpandedPanelGroupLayout(mostRecentLayout, [20, 40, 40]);
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
it("should resize the last panel in a group", () => {
|
|
355
|
-
assert(mostRecentLayout, "");
|
|
356
|
-
|
|
357
|
-
verifyExpandedPanelGroupLayout(mostRecentLayout, [20, 60, 20]);
|
|
358
|
-
act(() => {
|
|
359
|
-
rightPanelRef.current?.resize(40);
|
|
360
|
-
});
|
|
361
|
-
verifyExpandedPanelGroupLayout(mostRecentLayout, [20, 40, 40]);
|
|
362
|
-
});
|
|
363
|
-
});
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
describe("invariants", () => {
|
|
367
|
-
beforeEach(() => {
|
|
368
|
-
jest.spyOn(console, "error").mockImplementation(() => {
|
|
369
|
-
// Noop
|
|
370
|
-
});
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
it("should throw if default size is less than 0 or greater than 100", () => {
|
|
374
|
-
expect(() => {
|
|
375
|
-
act(() => {
|
|
376
|
-
root.render(
|
|
377
|
-
<PanelGroup direction="horizontal">
|
|
378
|
-
<Panel defaultSize={-1} />
|
|
379
|
-
</PanelGroup>
|
|
380
|
-
);
|
|
381
|
-
});
|
|
382
|
-
}).toThrow("Invalid layout");
|
|
383
|
-
|
|
384
|
-
expect(() => {
|
|
385
|
-
act(() => {
|
|
386
|
-
root.render(
|
|
387
|
-
<PanelGroup direction="horizontal">
|
|
388
|
-
<Panel defaultSize={101} />
|
|
389
|
-
</PanelGroup>
|
|
390
|
-
);
|
|
391
|
-
});
|
|
392
|
-
}).toThrow("Invalid layout");
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
it("should throw if rendered outside of a PanelGroup", () => {
|
|
396
|
-
expect(() => {
|
|
397
|
-
act(() => {
|
|
398
|
-
root.render(<Panel />);
|
|
399
|
-
});
|
|
400
|
-
}).toThrow(
|
|
401
|
-
"Panel components must be rendered within a PanelGroup container"
|
|
402
|
-
);
|
|
403
|
-
});
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
it("should support ...rest attributes", () => {
|
|
407
|
-
act(() => {
|
|
408
|
-
root.render(
|
|
409
|
-
<PanelGroup direction="horizontal">
|
|
410
|
-
<Panel data-test-name="foo" id="panel" tabIndex={123} title="bar" />
|
|
411
|
-
<PanelResizeHandle />
|
|
412
|
-
<Panel />
|
|
413
|
-
</PanelGroup>
|
|
414
|
-
);
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
const element = getPanelElement("panel", container);
|
|
418
|
-
assert(element, "");
|
|
419
|
-
expect(element.tabIndex).toBe(123);
|
|
420
|
-
expect(element.getAttribute("data-test-name")).toBe("foo");
|
|
421
|
-
expect(element.title).toBe("bar");
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
describe("constraints", () => {
|
|
425
|
-
it("should resize a collapsed panel if the collapsedSize prop changes", () => {
|
|
426
|
-
act(() => {
|
|
427
|
-
root.render(
|
|
428
|
-
<PanelGroup direction="horizontal">
|
|
429
|
-
<Panel
|
|
430
|
-
id="left"
|
|
431
|
-
collapsedSize={10}
|
|
432
|
-
collapsible
|
|
433
|
-
defaultSize={10}
|
|
434
|
-
minSize={25}
|
|
435
|
-
/>
|
|
436
|
-
<PanelResizeHandle />
|
|
437
|
-
<Panel id="middle" />
|
|
438
|
-
<PanelResizeHandle />
|
|
439
|
-
<Panel
|
|
440
|
-
id="right"
|
|
441
|
-
collapsedSize={10}
|
|
442
|
-
collapsible
|
|
443
|
-
defaultSize={10}
|
|
444
|
-
minSize={25}
|
|
445
|
-
/>
|
|
446
|
-
</PanelGroup>
|
|
447
|
-
);
|
|
448
|
-
});
|
|
449
|
-
|
|
450
|
-
let leftElement = getPanelElement("left", container);
|
|
451
|
-
let middleElement = getPanelElement("middle", container);
|
|
452
|
-
let rightElement = getPanelElement("right", container);
|
|
453
|
-
assert(leftElement, "");
|
|
454
|
-
assert(middleElement, "");
|
|
455
|
-
assert(rightElement, "");
|
|
456
|
-
expect(leftElement.getAttribute("data-panel-size")).toBe("10.0");
|
|
457
|
-
expect(middleElement.getAttribute("data-panel-size")).toBe("80.0");
|
|
458
|
-
expect(rightElement.getAttribute("data-panel-size")).toBe("10.0");
|
|
459
|
-
|
|
460
|
-
act(() => {
|
|
461
|
-
root.render(
|
|
462
|
-
<PanelGroup direction="horizontal">
|
|
463
|
-
<Panel id="left" collapsedSize={5} collapsible minSize={25} />
|
|
464
|
-
<PanelResizeHandle />
|
|
465
|
-
<Panel id="middle" />
|
|
466
|
-
<PanelResizeHandle />
|
|
467
|
-
<Panel id="right" collapsedSize={5} collapsible minSize={25} />
|
|
468
|
-
</PanelGroup>
|
|
469
|
-
);
|
|
470
|
-
});
|
|
471
|
-
|
|
472
|
-
expect(leftElement.getAttribute("data-panel-size")).toBe("5.0");
|
|
473
|
-
expect(middleElement.getAttribute("data-panel-size")).toBe("90.0");
|
|
474
|
-
expect(rightElement.getAttribute("data-panel-size")).toBe("5.0");
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
it("it should not expand a collapsed panel if other constraints change", () => {
|
|
478
|
-
act(() => {
|
|
479
|
-
root.render(
|
|
480
|
-
<PanelGroup direction="horizontal">
|
|
481
|
-
<Panel
|
|
482
|
-
id="left"
|
|
483
|
-
collapsedSize={10}
|
|
484
|
-
collapsible
|
|
485
|
-
defaultSize={10}
|
|
486
|
-
minSize={25}
|
|
487
|
-
/>
|
|
488
|
-
<PanelResizeHandle />
|
|
489
|
-
<Panel id="middle" />
|
|
490
|
-
<PanelResizeHandle />
|
|
491
|
-
<Panel
|
|
492
|
-
id="right"
|
|
493
|
-
collapsedSize={10}
|
|
494
|
-
collapsible
|
|
495
|
-
defaultSize={10}
|
|
496
|
-
minSize={25}
|
|
497
|
-
/>
|
|
498
|
-
</PanelGroup>
|
|
499
|
-
);
|
|
500
|
-
});
|
|
501
|
-
|
|
502
|
-
let leftElement = getPanelElement("left", container);
|
|
503
|
-
let middleElement = getPanelElement("middle", container);
|
|
504
|
-
let rightElement = getPanelElement("right", container);
|
|
505
|
-
assert(leftElement, "");
|
|
506
|
-
assert(middleElement, "");
|
|
507
|
-
assert(rightElement, "");
|
|
508
|
-
expect(leftElement.getAttribute("data-panel-size")).toBe("10.0");
|
|
509
|
-
expect(middleElement.getAttribute("data-panel-size")).toBe("80.0");
|
|
510
|
-
expect(rightElement.getAttribute("data-panel-size")).toBe("10.0");
|
|
511
|
-
|
|
512
|
-
act(() => {
|
|
513
|
-
root.render(
|
|
514
|
-
<PanelGroup direction="horizontal">
|
|
515
|
-
<Panel id="left" collapsedSize={10} collapsible minSize={20} />
|
|
516
|
-
<PanelResizeHandle />
|
|
517
|
-
<Panel id="middle" />
|
|
518
|
-
<PanelResizeHandle />
|
|
519
|
-
<Panel id="right" collapsedSize={10} collapsible minSize={20} />
|
|
520
|
-
</PanelGroup>
|
|
521
|
-
);
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
expect(leftElement.getAttribute("data-panel-size")).toBe("10.0");
|
|
525
|
-
expect(middleElement.getAttribute("data-panel-size")).toBe("80.0");
|
|
526
|
-
expect(rightElement.getAttribute("data-panel-size")).toBe("10.0");
|
|
527
|
-
});
|
|
528
|
-
|
|
529
|
-
it("should resize a panel if the minSize prop changes", () => {
|
|
530
|
-
act(() => {
|
|
531
|
-
root.render(
|
|
532
|
-
<PanelGroup direction="horizontal">
|
|
533
|
-
<Panel id="left" defaultSize={15} minSize={10} />
|
|
534
|
-
<PanelResizeHandle />
|
|
535
|
-
<Panel id="middle" />
|
|
536
|
-
<PanelResizeHandle />
|
|
537
|
-
<Panel id="right" defaultSize={15} minSize={10} />
|
|
538
|
-
</PanelGroup>
|
|
539
|
-
);
|
|
540
|
-
});
|
|
541
|
-
|
|
542
|
-
let leftElement = getPanelElement("left", container);
|
|
543
|
-
let middleElement = getPanelElement("middle", container);
|
|
544
|
-
let rightElement = getPanelElement("right", container);
|
|
545
|
-
assert(leftElement, "");
|
|
546
|
-
assert(middleElement, "");
|
|
547
|
-
assert(rightElement, "");
|
|
548
|
-
expect(leftElement.getAttribute("data-panel-size")).toBe("15.0");
|
|
549
|
-
expect(middleElement.getAttribute("data-panel-size")).toBe("70.0");
|
|
550
|
-
expect(rightElement.getAttribute("data-panel-size")).toBe("15.0");
|
|
551
|
-
|
|
552
|
-
act(() => {
|
|
553
|
-
root.render(
|
|
554
|
-
<PanelGroup direction="horizontal">
|
|
555
|
-
<Panel id="left" minSize={20} />
|
|
556
|
-
<PanelResizeHandle />
|
|
557
|
-
<Panel id="middle" />
|
|
558
|
-
<PanelResizeHandle />
|
|
559
|
-
<Panel id="right" minSize={20} />
|
|
560
|
-
</PanelGroup>
|
|
561
|
-
);
|
|
562
|
-
});
|
|
563
|
-
|
|
564
|
-
expect(leftElement.getAttribute("data-panel-size")).toBe("20.0");
|
|
565
|
-
expect(middleElement.getAttribute("data-panel-size")).toBe("60.0");
|
|
566
|
-
expect(rightElement.getAttribute("data-panel-size")).toBe("20.0");
|
|
567
|
-
});
|
|
568
|
-
|
|
569
|
-
it("should resize a panel if the maxSize prop changes", () => {
|
|
570
|
-
act(() => {
|
|
571
|
-
root.render(
|
|
572
|
-
<PanelGroup direction="horizontal">
|
|
573
|
-
<Panel id="left" defaultSize={25} maxSize={30} />
|
|
574
|
-
<PanelResizeHandle />
|
|
575
|
-
<Panel id="middle" />
|
|
576
|
-
<PanelResizeHandle />
|
|
577
|
-
<Panel id="right" defaultSize={25} maxSize={30} />
|
|
578
|
-
</PanelGroup>
|
|
579
|
-
);
|
|
580
|
-
});
|
|
581
|
-
|
|
582
|
-
let leftElement = getPanelElement("left", container);
|
|
583
|
-
let middleElement = getPanelElement("middle", container);
|
|
584
|
-
let rightElement = getPanelElement("right", container);
|
|
585
|
-
assert(leftElement, "");
|
|
586
|
-
assert(middleElement, "");
|
|
587
|
-
assert(rightElement, "");
|
|
588
|
-
expect(leftElement.getAttribute("data-panel-size")).toBe("25.0");
|
|
589
|
-
expect(middleElement.getAttribute("data-panel-size")).toBe("50.0");
|
|
590
|
-
expect(rightElement.getAttribute("data-panel-size")).toBe("25.0");
|
|
591
|
-
|
|
592
|
-
act(() => {
|
|
593
|
-
root.render(
|
|
594
|
-
<PanelGroup direction="horizontal">
|
|
595
|
-
<Panel id="left" maxSize={20} />
|
|
596
|
-
<PanelResizeHandle />
|
|
597
|
-
<Panel id="middle" />
|
|
598
|
-
<PanelResizeHandle />
|
|
599
|
-
<Panel id="right" maxSize={20} />
|
|
600
|
-
</PanelGroup>
|
|
601
|
-
);
|
|
602
|
-
});
|
|
603
|
-
|
|
604
|
-
expect(leftElement.getAttribute("data-panel-size")).toBe("20.0");
|
|
605
|
-
expect(middleElement.getAttribute("data-panel-size")).toBe("60.0");
|
|
606
|
-
expect(rightElement.getAttribute("data-panel-size")).toBe("20.0");
|
|
607
|
-
});
|
|
608
|
-
});
|
|
609
|
-
|
|
610
|
-
describe("callbacks", () => {
|
|
611
|
-
describe("onCollapse", () => {
|
|
612
|
-
it("should be called on mount if a panels initial size is 0", () => {
|
|
613
|
-
let onCollapseLeft = jest.fn();
|
|
614
|
-
let onCollapseRight = jest.fn();
|
|
615
|
-
|
|
616
|
-
act(() => {
|
|
617
|
-
root.render(
|
|
618
|
-
<PanelGroup direction="horizontal">
|
|
619
|
-
<Panel collapsible defaultSize={0} onCollapse={onCollapseLeft} />
|
|
620
|
-
<PanelResizeHandle />
|
|
621
|
-
<Panel collapsible onCollapse={onCollapseRight} />
|
|
622
|
-
</PanelGroup>
|
|
623
|
-
);
|
|
624
|
-
});
|
|
625
|
-
|
|
626
|
-
expect(onCollapseLeft).toHaveBeenCalledTimes(1);
|
|
627
|
-
expect(onCollapseRight).not.toHaveBeenCalled();
|
|
628
|
-
});
|
|
629
|
-
|
|
630
|
-
it("should be called when a panel is collapsed", () => {
|
|
631
|
-
let onCollapse = jest.fn();
|
|
632
|
-
|
|
633
|
-
let panelRef = createRef<ImperativePanelHandle>();
|
|
634
|
-
|
|
635
|
-
act(() => {
|
|
636
|
-
root.render(
|
|
637
|
-
<PanelGroup direction="horizontal">
|
|
638
|
-
<Panel collapsible onCollapse={onCollapse} ref={panelRef} />
|
|
639
|
-
<PanelResizeHandle />
|
|
640
|
-
<Panel />
|
|
641
|
-
</PanelGroup>
|
|
642
|
-
);
|
|
643
|
-
});
|
|
644
|
-
|
|
645
|
-
expect(onCollapse).not.toHaveBeenCalled();
|
|
646
|
-
|
|
647
|
-
act(() => {
|
|
648
|
-
panelRef.current?.collapse();
|
|
649
|
-
});
|
|
650
|
-
|
|
651
|
-
expect(onCollapse).toHaveBeenCalledTimes(1);
|
|
652
|
-
});
|
|
653
|
-
|
|
654
|
-
it("should be called with collapsedSizes that have many decimal places", () => {
|
|
655
|
-
let onCollapse = jest.fn();
|
|
656
|
-
|
|
657
|
-
let panelRef = createRef<ImperativePanelHandle>();
|
|
658
|
-
|
|
659
|
-
act(() => {
|
|
660
|
-
root.render(
|
|
661
|
-
<PanelGroup direction="horizontal">
|
|
662
|
-
<Panel
|
|
663
|
-
collapsible
|
|
664
|
-
onCollapse={onCollapse}
|
|
665
|
-
collapsedSize={3.8764385221078133}
|
|
666
|
-
minSize={10}
|
|
667
|
-
ref={panelRef}
|
|
668
|
-
/>
|
|
669
|
-
<PanelResizeHandle />
|
|
670
|
-
<Panel />
|
|
671
|
-
</PanelGroup>
|
|
672
|
-
);
|
|
673
|
-
});
|
|
674
|
-
expect(onCollapse).not.toHaveBeenCalled();
|
|
675
|
-
|
|
676
|
-
act(() => {
|
|
677
|
-
panelRef.current?.collapse();
|
|
678
|
-
});
|
|
679
|
-
expect(onCollapse).toHaveBeenCalledTimes(1);
|
|
680
|
-
|
|
681
|
-
act(() => {
|
|
682
|
-
panelRef.current?.expand();
|
|
683
|
-
});
|
|
684
|
-
expect(onCollapse).toHaveBeenCalledTimes(1);
|
|
685
|
-
|
|
686
|
-
act(() => {
|
|
687
|
-
panelRef.current?.collapse();
|
|
688
|
-
});
|
|
689
|
-
expect(onCollapse).toHaveBeenCalledTimes(2);
|
|
690
|
-
});
|
|
691
|
-
});
|
|
692
|
-
|
|
693
|
-
describe("onExpand", () => {
|
|
694
|
-
it("should be called on mount if a collapsible panels initial size is not 0", () => {
|
|
695
|
-
let onExpandLeft = jest.fn();
|
|
696
|
-
let onExpandRight = jest.fn();
|
|
697
|
-
|
|
698
|
-
act(() => {
|
|
699
|
-
root.render(
|
|
700
|
-
<PanelGroup direction="horizontal">
|
|
701
|
-
<Panel collapsible onExpand={onExpandLeft} />
|
|
702
|
-
<PanelResizeHandle />
|
|
703
|
-
<Panel onExpand={onExpandRight} />
|
|
704
|
-
</PanelGroup>
|
|
705
|
-
);
|
|
706
|
-
});
|
|
707
|
-
|
|
708
|
-
expect(onExpandLeft).toHaveBeenCalledTimes(1);
|
|
709
|
-
expect(onExpandRight).not.toHaveBeenCalled();
|
|
710
|
-
});
|
|
711
|
-
|
|
712
|
-
it("should be called when a collapsible panel is expanded", () => {
|
|
713
|
-
let onExpand = jest.fn();
|
|
714
|
-
|
|
715
|
-
let panelRef = createRef<ImperativePanelHandle>();
|
|
716
|
-
|
|
717
|
-
act(() => {
|
|
718
|
-
root.render(
|
|
719
|
-
<PanelGroup direction="horizontal">
|
|
720
|
-
<Panel
|
|
721
|
-
collapsible
|
|
722
|
-
defaultSize={0}
|
|
723
|
-
onExpand={onExpand}
|
|
724
|
-
ref={panelRef}
|
|
725
|
-
/>
|
|
726
|
-
<PanelResizeHandle />
|
|
727
|
-
<Panel />
|
|
728
|
-
</PanelGroup>
|
|
729
|
-
);
|
|
730
|
-
});
|
|
731
|
-
|
|
732
|
-
expect(onExpand).not.toHaveBeenCalled();
|
|
733
|
-
|
|
734
|
-
act(() => {
|
|
735
|
-
panelRef.current?.resize(25);
|
|
736
|
-
});
|
|
737
|
-
|
|
738
|
-
expect(onExpand).toHaveBeenCalledTimes(1);
|
|
739
|
-
});
|
|
740
|
-
|
|
741
|
-
it("should be called with collapsedSizes that have many decimal places", () => {
|
|
742
|
-
let onExpand = jest.fn();
|
|
743
|
-
|
|
744
|
-
let panelRef = createRef<ImperativePanelHandle>();
|
|
745
|
-
|
|
746
|
-
act(() => {
|
|
747
|
-
root.render(
|
|
748
|
-
<PanelGroup direction="horizontal">
|
|
749
|
-
<Panel
|
|
750
|
-
collapsible
|
|
751
|
-
collapsedSize={3.8764385221078133}
|
|
752
|
-
defaultSize={3.8764385221078133}
|
|
753
|
-
minSize={10}
|
|
754
|
-
onExpand={onExpand}
|
|
755
|
-
ref={panelRef}
|
|
756
|
-
/>
|
|
757
|
-
<PanelResizeHandle />
|
|
758
|
-
<Panel />
|
|
759
|
-
</PanelGroup>
|
|
760
|
-
);
|
|
761
|
-
});
|
|
762
|
-
expect(onExpand).not.toHaveBeenCalled();
|
|
763
|
-
|
|
764
|
-
act(() => {
|
|
765
|
-
panelRef.current?.resize(25);
|
|
766
|
-
});
|
|
767
|
-
expect(onExpand).toHaveBeenCalledTimes(1);
|
|
768
|
-
|
|
769
|
-
act(() => {
|
|
770
|
-
panelRef.current?.collapse();
|
|
771
|
-
});
|
|
772
|
-
expect(onExpand).toHaveBeenCalledTimes(1);
|
|
773
|
-
|
|
774
|
-
act(() => {
|
|
775
|
-
panelRef.current?.expand();
|
|
776
|
-
});
|
|
777
|
-
expect(onExpand).toHaveBeenCalledTimes(2);
|
|
778
|
-
});
|
|
779
|
-
});
|
|
780
|
-
|
|
781
|
-
describe("onResize", () => {
|
|
782
|
-
it("should be called on mount", () => {
|
|
783
|
-
let onResizeLeft = jest.fn();
|
|
784
|
-
let onResizeMiddle = jest.fn();
|
|
785
|
-
let onResizeRight = jest.fn();
|
|
786
|
-
|
|
787
|
-
act(() => {
|
|
788
|
-
root.render(
|
|
789
|
-
<PanelGroup direction="horizontal">
|
|
790
|
-
<Panel id="left" onResize={onResizeLeft} order={1} />
|
|
791
|
-
<PanelResizeHandle />
|
|
792
|
-
<Panel
|
|
793
|
-
defaultSize={50}
|
|
794
|
-
id="middle"
|
|
795
|
-
onResize={onResizeMiddle}
|
|
796
|
-
order={2}
|
|
797
|
-
/>
|
|
798
|
-
<PanelResizeHandle />
|
|
799
|
-
<Panel id="right" onResize={onResizeRight} order={3} />
|
|
800
|
-
</PanelGroup>
|
|
801
|
-
);
|
|
802
|
-
});
|
|
803
|
-
|
|
804
|
-
expect(onResizeLeft).toHaveBeenCalledTimes(1);
|
|
805
|
-
expect(onResizeLeft).toHaveBeenCalledWith(25, undefined);
|
|
806
|
-
expect(onResizeMiddle).toHaveBeenCalledTimes(1);
|
|
807
|
-
expect(onResizeMiddle).toHaveBeenCalledWith(50, undefined);
|
|
808
|
-
expect(onResizeRight).toHaveBeenCalledTimes(1);
|
|
809
|
-
expect(onResizeRight).toHaveBeenCalledWith(25, undefined);
|
|
810
|
-
});
|
|
811
|
-
|
|
812
|
-
it("should be called when a panel is added or removed from the group", () => {
|
|
813
|
-
let onResizeLeft = jest.fn();
|
|
814
|
-
let onResizeMiddle = jest.fn();
|
|
815
|
-
let onResizeRight = jest.fn();
|
|
816
|
-
|
|
817
|
-
act(() => {
|
|
818
|
-
root.render(
|
|
819
|
-
<PanelGroup direction="horizontal">
|
|
820
|
-
<Panel
|
|
821
|
-
id="middle"
|
|
822
|
-
key="middle"
|
|
823
|
-
onResize={onResizeMiddle}
|
|
824
|
-
order={2}
|
|
825
|
-
/>
|
|
826
|
-
</PanelGroup>
|
|
827
|
-
);
|
|
828
|
-
});
|
|
829
|
-
|
|
830
|
-
expect(onResizeLeft).not.toHaveBeenCalled();
|
|
831
|
-
expect(onResizeMiddle).toHaveBeenCalledWith(100, undefined);
|
|
832
|
-
expect(onResizeRight).not.toHaveBeenCalled();
|
|
833
|
-
|
|
834
|
-
onResizeLeft.mockReset();
|
|
835
|
-
onResizeMiddle.mockReset();
|
|
836
|
-
onResizeRight.mockReset();
|
|
837
|
-
|
|
838
|
-
act(() => {
|
|
839
|
-
root.render(
|
|
840
|
-
<PanelGroup direction="horizontal">
|
|
841
|
-
<Panel
|
|
842
|
-
id="left"
|
|
843
|
-
key="left"
|
|
844
|
-
maxSize={25}
|
|
845
|
-
minSize={25}
|
|
846
|
-
onResize={onResizeLeft}
|
|
847
|
-
order={1}
|
|
848
|
-
/>
|
|
849
|
-
<PanelResizeHandle />
|
|
850
|
-
<Panel
|
|
851
|
-
id="middle"
|
|
852
|
-
key="middle"
|
|
853
|
-
onResize={onResizeMiddle}
|
|
854
|
-
order={2}
|
|
855
|
-
/>
|
|
856
|
-
<PanelResizeHandle />
|
|
857
|
-
<Panel
|
|
858
|
-
id="right"
|
|
859
|
-
key="right"
|
|
860
|
-
maxSize={25}
|
|
861
|
-
minSize={25}
|
|
862
|
-
onResize={onResizeRight}
|
|
863
|
-
order={3}
|
|
864
|
-
/>
|
|
865
|
-
</PanelGroup>
|
|
866
|
-
);
|
|
867
|
-
});
|
|
868
|
-
|
|
869
|
-
expect(onResizeLeft).toHaveBeenCalledTimes(1);
|
|
870
|
-
expect(onResizeLeft).toHaveBeenCalledWith(25, undefined);
|
|
871
|
-
expect(onResizeMiddle).toHaveBeenCalledTimes(1);
|
|
872
|
-
expect(onResizeMiddle).toHaveBeenCalledWith(50, 100);
|
|
873
|
-
expect(onResizeRight).toHaveBeenCalledTimes(1);
|
|
874
|
-
expect(onResizeRight).toHaveBeenCalledWith(25, undefined);
|
|
875
|
-
|
|
876
|
-
onResizeLeft.mockReset();
|
|
877
|
-
onResizeMiddle.mockReset();
|
|
878
|
-
onResizeRight.mockReset();
|
|
879
|
-
|
|
880
|
-
act(() => {
|
|
881
|
-
root.render(
|
|
882
|
-
<PanelGroup direction="horizontal">
|
|
883
|
-
<Panel
|
|
884
|
-
id="left"
|
|
885
|
-
key="left"
|
|
886
|
-
maxSize={25}
|
|
887
|
-
minSize={25}
|
|
888
|
-
onResize={onResizeLeft}
|
|
889
|
-
order={1}
|
|
890
|
-
/>
|
|
891
|
-
<PanelResizeHandle />
|
|
892
|
-
<Panel
|
|
893
|
-
id="middle"
|
|
894
|
-
key="middle"
|
|
895
|
-
onResize={onResizeMiddle}
|
|
896
|
-
order={2}
|
|
897
|
-
/>
|
|
898
|
-
</PanelGroup>
|
|
899
|
-
);
|
|
900
|
-
});
|
|
901
|
-
|
|
902
|
-
expect(onResizeLeft).not.toHaveBeenCalled();
|
|
903
|
-
expect(onResizeMiddle).toHaveBeenCalledTimes(1);
|
|
904
|
-
expect(onResizeMiddle).toHaveBeenCalledWith(75, 50);
|
|
905
|
-
expect(onResizeRight).not.toHaveBeenCalled();
|
|
906
|
-
});
|
|
907
|
-
});
|
|
908
|
-
|
|
909
|
-
it("should support sizes with many decimal places", () => {
|
|
910
|
-
let panelRef = createRef<ImperativePanelHandle>();
|
|
911
|
-
let onResize = jest.fn();
|
|
912
|
-
|
|
913
|
-
act(() => {
|
|
914
|
-
root.render(
|
|
915
|
-
<PanelGroup direction="horizontal">
|
|
916
|
-
<Panel onResize={onResize} ref={panelRef} />
|
|
917
|
-
<PanelResizeHandle />
|
|
918
|
-
<Panel />
|
|
919
|
-
</PanelGroup>
|
|
920
|
-
);
|
|
921
|
-
});
|
|
922
|
-
expect(onResize).toHaveBeenCalledTimes(1);
|
|
923
|
-
|
|
924
|
-
act(() => {
|
|
925
|
-
panelRef.current?.resize(3.8764385221078133);
|
|
926
|
-
});
|
|
927
|
-
expect(onResize).toHaveBeenCalledTimes(2);
|
|
928
|
-
|
|
929
|
-
// An overly-high precision change should be ignored
|
|
930
|
-
act(() => {
|
|
931
|
-
panelRef.current?.resize(3.8764385221078132);
|
|
932
|
-
});
|
|
933
|
-
expect(onResize).toHaveBeenCalledTimes(2);
|
|
934
|
-
});
|
|
935
|
-
});
|
|
936
|
-
|
|
937
|
-
describe("data attributes", () => {
|
|
938
|
-
it("should initialize with the correct props based attributes", () => {
|
|
939
|
-
act(() => {
|
|
940
|
-
root.render(
|
|
941
|
-
<PanelGroup direction="horizontal" id="test-group">
|
|
942
|
-
<Panel defaultSize={75} id="left-panel" />
|
|
943
|
-
<PanelResizeHandle />
|
|
944
|
-
<Panel collapsible id="right-panel" />
|
|
945
|
-
</PanelGroup>
|
|
946
|
-
);
|
|
947
|
-
});
|
|
948
|
-
|
|
949
|
-
const leftElement = getPanelElement("left-panel", container);
|
|
950
|
-
const rightElement = getPanelElement("right-panel", container);
|
|
951
|
-
|
|
952
|
-
assert(leftElement, "");
|
|
953
|
-
assert(rightElement, "");
|
|
954
|
-
|
|
955
|
-
verifyAttribute(leftElement, "data-panel", "");
|
|
956
|
-
verifyAttribute(leftElement, "data-panel-id", "left-panel");
|
|
957
|
-
verifyAttribute(leftElement, "data-panel-group-id", "test-group");
|
|
958
|
-
verifyAttribute(leftElement, "data-panel-size", "75.0");
|
|
959
|
-
verifyAttribute(leftElement, "data-panel-collapsible", null);
|
|
960
|
-
|
|
961
|
-
verifyAttribute(rightElement, "data-panel", "");
|
|
962
|
-
verifyAttribute(rightElement, "data-panel-id", "right-panel");
|
|
963
|
-
verifyAttribute(rightElement, "data-panel-group-id", "test-group");
|
|
964
|
-
verifyAttribute(rightElement, "data-panel-size", "25.0");
|
|
965
|
-
verifyAttribute(rightElement, "data-panel-collapsible", "true");
|
|
966
|
-
});
|
|
967
|
-
|
|
968
|
-
it("should update the data-panel-size attribute when the panel resizes", () => {
|
|
969
|
-
const leftPanelRef = createRef<ImperativePanelHandle>();
|
|
970
|
-
|
|
971
|
-
act(() => {
|
|
972
|
-
root.render(
|
|
973
|
-
<PanelGroup direction="horizontal" id="test-group">
|
|
974
|
-
<Panel defaultSize={75} id="left-panel" ref={leftPanelRef} />
|
|
975
|
-
<PanelResizeHandle />
|
|
976
|
-
<Panel collapsible id="right-panel" />
|
|
977
|
-
</PanelGroup>
|
|
978
|
-
);
|
|
979
|
-
});
|
|
980
|
-
|
|
981
|
-
const leftElement = getPanelElement("left-panel", container);
|
|
982
|
-
const rightElement = getPanelElement("right-panel", container);
|
|
983
|
-
|
|
984
|
-
assert(leftElement, "");
|
|
985
|
-
assert(rightElement, "");
|
|
986
|
-
|
|
987
|
-
verifyAttribute(leftElement, "data-panel-size", "75.0");
|
|
988
|
-
verifyAttribute(rightElement, "data-panel-size", "25.0");
|
|
989
|
-
|
|
990
|
-
act(() => {
|
|
991
|
-
leftPanelRef.current?.resize(30);
|
|
992
|
-
});
|
|
993
|
-
|
|
994
|
-
verifyAttribute(leftElement, "data-panel-size", "30.0");
|
|
995
|
-
verifyAttribute(rightElement, "data-panel-size", "70.0");
|
|
996
|
-
});
|
|
997
|
-
});
|
|
998
|
-
|
|
999
|
-
describe("a11y", () => {
|
|
1000
|
-
it("should pass explicit id prop to DOM", () => {
|
|
1001
|
-
act(() => {
|
|
1002
|
-
root.render(
|
|
1003
|
-
<PanelGroup direction="horizontal">
|
|
1004
|
-
<Panel id="explicit-id" />
|
|
1005
|
-
</PanelGroup>
|
|
1006
|
-
);
|
|
1007
|
-
});
|
|
1008
|
-
|
|
1009
|
-
const element = container.querySelector("[data-panel]");
|
|
1010
|
-
|
|
1011
|
-
expect(element).not.toBeNull();
|
|
1012
|
-
expect(element?.getAttribute("id")).toBe("explicit-id");
|
|
1013
|
-
});
|
|
1014
|
-
|
|
1015
|
-
it("should not pass auto-generated id prop to DOM", () => {
|
|
1016
|
-
act(() => {
|
|
1017
|
-
root.render(
|
|
1018
|
-
<PanelGroup direction="horizontal">
|
|
1019
|
-
<Panel />
|
|
1020
|
-
</PanelGroup>
|
|
1021
|
-
);
|
|
1022
|
-
});
|
|
1023
|
-
|
|
1024
|
-
const element = container.querySelector("[data-panel]");
|
|
1025
|
-
|
|
1026
|
-
expect(element).not.toBeNull();
|
|
1027
|
-
expect(element?.getAttribute("id")).toBeNull();
|
|
1028
|
-
});
|
|
1029
|
-
});
|
|
1030
|
-
|
|
1031
|
-
describe("DEV warnings", () => {
|
|
1032
|
-
it("should warn about server rendered panels with no default size", () => {
|
|
1033
|
-
jest.resetModules();
|
|
1034
|
-
jest.mock("#is-browser", () => ({ isBrowser: false }));
|
|
1035
|
-
|
|
1036
|
-
const { TextEncoder } = require("util");
|
|
1037
|
-
global.TextEncoder = TextEncoder;
|
|
1038
|
-
|
|
1039
|
-
const { renderToStaticMarkup } = require("react-dom/server.browser");
|
|
1040
|
-
const { act } = require("react-dom/test-utils");
|
|
1041
|
-
const Panel = require("./Panel").Panel;
|
|
1042
|
-
const PanelGroup = require("./PanelGroup").PanelGroup;
|
|
1043
|
-
const PanelResizeHandle =
|
|
1044
|
-
require("./PanelResizeHandle").PanelResizeHandle;
|
|
1045
|
-
|
|
1046
|
-
act(() => {
|
|
1047
|
-
// No warning expected if default sizes provided
|
|
1048
|
-
renderToStaticMarkup(
|
|
1049
|
-
<PanelGroup direction="horizontal">
|
|
1050
|
-
<Panel defaultSize={100} />
|
|
1051
|
-
<PanelResizeHandle />
|
|
1052
|
-
<Panel defaultSize={1_000} />
|
|
1053
|
-
</PanelGroup>
|
|
1054
|
-
);
|
|
1055
|
-
});
|
|
1056
|
-
|
|
1057
|
-
expectWarning(
|
|
1058
|
-
"Panel defaultSize prop recommended to avoid layout shift after server rendering"
|
|
1059
|
-
);
|
|
1060
|
-
|
|
1061
|
-
act(() => {
|
|
1062
|
-
renderToStaticMarkup(
|
|
1063
|
-
<PanelGroup direction="horizontal">
|
|
1064
|
-
<Panel id="one" />
|
|
1065
|
-
</PanelGroup>
|
|
1066
|
-
);
|
|
1067
|
-
});
|
|
1068
|
-
});
|
|
1069
|
-
|
|
1070
|
-
it("should warn if invalid sizes are specified declaratively", () => {
|
|
1071
|
-
expectWarning("default size should not be less than 0");
|
|
1072
|
-
|
|
1073
|
-
act(() => {
|
|
1074
|
-
root.render(
|
|
1075
|
-
<PanelGroup direction="horizontal" key="collapsedSize">
|
|
1076
|
-
<Panel defaultSize={-1} />
|
|
1077
|
-
<PanelResizeHandle />
|
|
1078
|
-
<Panel />
|
|
1079
|
-
</PanelGroup>
|
|
1080
|
-
);
|
|
1081
|
-
});
|
|
1082
|
-
});
|
|
1083
|
-
});
|
|
1084
|
-
});
|