react-resizable-panels 2.1.6 → 2.1.8

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.
Files changed (92) hide show
  1. package/README.md +4 -0
  2. package/dist/declarations/src/Panel.d.ts +1 -1
  3. package/dist/declarations/src/PanelGroup.d.ts +1 -1
  4. package/dist/declarations/src/PanelResizeHandle.d.ts +6 -3
  5. package/dist/react-resizable-panels.browser.cjs.js +90 -94
  6. package/dist/react-resizable-panels.browser.development.cjs.js +90 -94
  7. package/dist/react-resizable-panels.browser.development.esm.js +38 -41
  8. package/dist/react-resizable-panels.browser.esm.js +38 -41
  9. package/dist/react-resizable-panels.cjs.js +90 -94
  10. package/dist/react-resizable-panels.development.cjs.js +90 -94
  11. package/dist/react-resizable-panels.development.esm.js +38 -41
  12. package/dist/react-resizable-panels.development.node.cjs.js +89 -92
  13. package/dist/react-resizable-panels.development.node.esm.js +37 -39
  14. package/dist/react-resizable-panels.esm.js +38 -41
  15. package/dist/react-resizable-panels.node.cjs.js +89 -92
  16. package/dist/react-resizable-panels.node.esm.js +37 -39
  17. package/package.json +7 -2
  18. package/.eslintrc.cjs +0 -27
  19. package/CHANGELOG.md +0 -574
  20. package/dist/declarations/src/vendor/react.d.ts +0 -7
  21. package/jest.config.js +0 -10
  22. package/src/Panel.test.tsx +0 -1084
  23. package/src/Panel.ts +0 -259
  24. package/src/PanelGroup.test.tsx +0 -443
  25. package/src/PanelGroup.ts +0 -999
  26. package/src/PanelGroupContext.ts +0 -42
  27. package/src/PanelResizeHandle.test.tsx +0 -367
  28. package/src/PanelResizeHandle.ts +0 -246
  29. package/src/PanelResizeHandleRegistry.ts +0 -336
  30. package/src/constants.ts +0 -1
  31. package/src/env-conditions/browser.ts +0 -1
  32. package/src/env-conditions/development.ts +0 -1
  33. package/src/env-conditions/node.ts +0 -1
  34. package/src/env-conditions/production.ts +0 -1
  35. package/src/env-conditions/unknown.ts +0 -1
  36. package/src/hooks/useForceUpdate.ts +0 -7
  37. package/src/hooks/useIsomorphicEffect.ts +0 -8
  38. package/src/hooks/useUniqueId.ts +0 -19
  39. package/src/hooks/useWindowSplitterBehavior.ts +0 -90
  40. package/src/hooks/useWindowSplitterPanelGroupBehavior.ts +0 -201
  41. package/src/index.ts +0 -77
  42. package/src/types.ts +0 -5
  43. package/src/utils/adjustLayoutByDelta.test.ts +0 -2061
  44. package/src/utils/adjustLayoutByDelta.ts +0 -308
  45. package/src/utils/arrays.ts +0 -13
  46. package/src/utils/assert.ts +0 -10
  47. package/src/utils/calculateAriaValues.test.ts +0 -106
  48. package/src/utils/calculateAriaValues.ts +0 -45
  49. package/src/utils/calculateDeltaPercentage.ts +0 -63
  50. package/src/utils/calculateDragOffsetPercentage.ts +0 -40
  51. package/src/utils/calculateUnsafeDefaultLayout.test.ts +0 -87
  52. package/src/utils/calculateUnsafeDefaultLayout.ts +0 -50
  53. package/src/utils/callPanelCallbacks.ts +0 -49
  54. package/src/utils/compareLayouts.test.ts +0 -9
  55. package/src/utils/compareLayouts.ts +0 -12
  56. package/src/utils/computePanelFlexBoxStyle.test.ts +0 -123
  57. package/src/utils/computePanelFlexBoxStyle.ts +0 -50
  58. package/src/utils/csp.ts +0 -9
  59. package/src/utils/cursor.ts +0 -103
  60. package/src/utils/debounce.ts +0 -18
  61. package/src/utils/determinePivotIndices.ts +0 -15
  62. package/src/utils/dom/getPanelElement.ts +0 -10
  63. package/src/utils/dom/getPanelElementsForGroup.ts +0 -8
  64. package/src/utils/dom/getPanelGroupElement.ts +0 -21
  65. package/src/utils/dom/getResizeHandleElement.ts +0 -10
  66. package/src/utils/dom/getResizeHandleElementIndex.ts +0 -13
  67. package/src/utils/dom/getResizeHandleElementsForGroup.ts +0 -10
  68. package/src/utils/dom/getResizeHandlePanelIds.ts +0 -19
  69. package/src/utils/events/getResizeEventCoordinates.ts +0 -23
  70. package/src/utils/events/getResizeEventCursorPosition.ts +0 -14
  71. package/src/utils/events/index.ts +0 -13
  72. package/src/utils/getInputType.ts +0 -5
  73. package/src/utils/initializeDefaultStorage.ts +0 -26
  74. package/src/utils/numbers/fuzzyCompareNumbers.test.ts +0 -16
  75. package/src/utils/numbers/fuzzyCompareNumbers.ts +0 -21
  76. package/src/utils/numbers/fuzzyLayoutsEqual.ts +0 -22
  77. package/src/utils/numbers/fuzzyNumbersEqual.ts +0 -9
  78. package/src/utils/rects/getIntersectingRectangle.test.ts +0 -198
  79. package/src/utils/rects/getIntersectingRectangle.ts +0 -28
  80. package/src/utils/rects/intersects.test.ts +0 -197
  81. package/src/utils/rects/intersects.ts +0 -23
  82. package/src/utils/rects/types.ts +0 -6
  83. package/src/utils/resizePanel.test.ts +0 -59
  84. package/src/utils/resizePanel.ts +0 -47
  85. package/src/utils/serialization.ts +0 -87
  86. package/src/utils/test-utils.ts +0 -205
  87. package/src/utils/validatePanelConstraints.test.ts +0 -143
  88. package/src/utils/validatePanelConstraints.ts +0 -69
  89. package/src/utils/validatePanelGroupLayout.test.ts +0 -148
  90. package/src/utils/validatePanelGroupLayout.ts +0 -95
  91. package/src/vendor/react.ts +0 -73
  92. package/src/vendor/stacking-order.ts +0 -139
package/src/Panel.ts DELETED
@@ -1,259 +0,0 @@
1
- import { isBrowser } from "#is-browser";
2
- import { isDevelopment } from "#is-development";
3
- import { PanelGroupContext } from "./PanelGroupContext";
4
- import useIsomorphicLayoutEffect from "./hooks/useIsomorphicEffect";
5
- import useUniqueId from "./hooks/useUniqueId";
6
- import {
7
- ForwardedRef,
8
- HTMLAttributes,
9
- PropsWithChildren,
10
- ReactElement,
11
- createElement,
12
- forwardRef,
13
- useContext,
14
- useImperativeHandle,
15
- useRef,
16
- } from "./vendor/react";
17
-
18
- export type PanelOnCollapse = () => void;
19
- export type PanelOnExpand = () => void;
20
- export type PanelOnResize = (
21
- size: number,
22
- prevSize: number | undefined
23
- ) => void;
24
-
25
- export type PanelCallbacks = {
26
- onCollapse?: PanelOnCollapse;
27
- onExpand?: PanelOnExpand;
28
- onResize?: PanelOnResize;
29
- };
30
-
31
- export type PanelConstraints = {
32
- collapsedSize?: number | undefined;
33
- collapsible?: boolean | undefined;
34
- defaultSize?: number | undefined;
35
- maxSize?: number | undefined;
36
- minSize?: number | undefined;
37
- };
38
-
39
- export type PanelData = {
40
- callbacks: PanelCallbacks;
41
- constraints: PanelConstraints;
42
- id: string;
43
- idIsFromProps: boolean;
44
- order: number | undefined;
45
- };
46
-
47
- export type ImperativePanelHandle = {
48
- collapse: () => void;
49
- expand: (minSize?: number) => void;
50
- getId(): string;
51
- getSize(): number;
52
- isCollapsed: () => boolean;
53
- isExpanded: () => boolean;
54
- resize: (size: number) => void;
55
- };
56
-
57
- export type PanelProps<
58
- T extends keyof HTMLElementTagNameMap = keyof HTMLElementTagNameMap,
59
- > = Omit<HTMLAttributes<HTMLElementTagNameMap[T]>, "id" | "onResize"> &
60
- PropsWithChildren<{
61
- className?: string;
62
- collapsedSize?: number | undefined;
63
- collapsible?: boolean | undefined;
64
- defaultSize?: number | undefined;
65
- id?: string;
66
- maxSize?: number | undefined;
67
- minSize?: number | undefined;
68
- onCollapse?: PanelOnCollapse;
69
- onExpand?: PanelOnExpand;
70
- onResize?: PanelOnResize;
71
- order?: number;
72
- style?: object;
73
- tagName?: T;
74
- }>;
75
-
76
- export function PanelWithForwardedRef({
77
- children,
78
- className: classNameFromProps = "",
79
- collapsedSize,
80
- collapsible,
81
- defaultSize,
82
- forwardedRef,
83
- id: idFromProps,
84
- maxSize,
85
- minSize,
86
- onCollapse,
87
- onExpand,
88
- onResize,
89
- order,
90
- style: styleFromProps,
91
- tagName: Type = "div",
92
- ...rest
93
- }: PanelProps & {
94
- forwardedRef: ForwardedRef<ImperativePanelHandle>;
95
- }): ReactElement {
96
- const context = useContext(PanelGroupContext);
97
- if (context === null) {
98
- throw Error(
99
- `Panel components must be rendered within a PanelGroup container`
100
- );
101
- }
102
-
103
- const {
104
- collapsePanel,
105
- expandPanel,
106
- getPanelSize,
107
- getPanelStyle,
108
- groupId,
109
- isPanelCollapsed,
110
- reevaluatePanelConstraints,
111
- registerPanel,
112
- resizePanel,
113
- unregisterPanel,
114
- } = context;
115
-
116
- const panelId = useUniqueId(idFromProps);
117
-
118
- const panelDataRef = useRef<PanelData>({
119
- callbacks: {
120
- onCollapse,
121
- onExpand,
122
- onResize,
123
- },
124
- constraints: {
125
- collapsedSize,
126
- collapsible,
127
- defaultSize,
128
- maxSize,
129
- minSize,
130
- },
131
- id: panelId,
132
- idIsFromProps: idFromProps !== undefined,
133
- order,
134
- });
135
-
136
- const devWarningsRef = useRef<{
137
- didLogMissingDefaultSizeWarning: boolean;
138
- }>({
139
- didLogMissingDefaultSizeWarning: false,
140
- });
141
-
142
- // Normally we wouldn't log a warning during render,
143
- // but effects don't run on the server, so we can't do it there
144
- if (isDevelopment) {
145
- if (!devWarningsRef.current.didLogMissingDefaultSizeWarning) {
146
- if (!isBrowser && defaultSize == null) {
147
- devWarningsRef.current.didLogMissingDefaultSizeWarning = true;
148
- console.warn(
149
- `WARNING: Panel defaultSize prop recommended to avoid layout shift after server rendering`
150
- );
151
- }
152
- }
153
- }
154
-
155
- useIsomorphicLayoutEffect(() => {
156
- const { callbacks, constraints } = panelDataRef.current;
157
-
158
- const prevConstraints = { ...constraints };
159
-
160
- panelDataRef.current.id = panelId;
161
- panelDataRef.current.idIsFromProps = idFromProps !== undefined;
162
- panelDataRef.current.order = order;
163
-
164
- callbacks.onCollapse = onCollapse;
165
- callbacks.onExpand = onExpand;
166
- callbacks.onResize = onResize;
167
-
168
- constraints.collapsedSize = collapsedSize;
169
- constraints.collapsible = collapsible;
170
- constraints.defaultSize = defaultSize;
171
- constraints.maxSize = maxSize;
172
- constraints.minSize = minSize;
173
-
174
- // If constraints have changed, we should revisit panel sizes.
175
- // This is uncommon but may happen if people are trying to implement pixel based constraints.
176
- if (
177
- prevConstraints.collapsedSize !== constraints.collapsedSize ||
178
- prevConstraints.collapsible !== constraints.collapsible ||
179
- prevConstraints.maxSize !== constraints.maxSize ||
180
- prevConstraints.minSize !== constraints.minSize
181
- ) {
182
- reevaluatePanelConstraints(panelDataRef.current, prevConstraints);
183
- }
184
- });
185
-
186
- useIsomorphicLayoutEffect(() => {
187
- const panelData = panelDataRef.current;
188
-
189
- registerPanel(panelData);
190
-
191
- return () => {
192
- unregisterPanel(panelData);
193
- };
194
- }, [order, panelId, registerPanel, unregisterPanel]);
195
-
196
- useImperativeHandle(
197
- forwardedRef,
198
- () => ({
199
- collapse: () => {
200
- collapsePanel(panelDataRef.current);
201
- },
202
- expand: (minSize?: number) => {
203
- expandPanel(panelDataRef.current, minSize);
204
- },
205
- getId() {
206
- return panelId;
207
- },
208
- getSize() {
209
- return getPanelSize(panelDataRef.current);
210
- },
211
- isCollapsed() {
212
- return isPanelCollapsed(panelDataRef.current);
213
- },
214
- isExpanded() {
215
- return !isPanelCollapsed(panelDataRef.current);
216
- },
217
- resize: (size: number) => {
218
- resizePanel(panelDataRef.current, size);
219
- },
220
- }),
221
- [
222
- collapsePanel,
223
- expandPanel,
224
- getPanelSize,
225
- isPanelCollapsed,
226
- panelId,
227
- resizePanel,
228
- ]
229
- );
230
-
231
- const style = getPanelStyle(panelDataRef.current, defaultSize);
232
-
233
- return createElement(Type, {
234
- ...rest,
235
-
236
- children,
237
- className: classNameFromProps,
238
- id: idFromProps,
239
- style: {
240
- ...style,
241
- ...styleFromProps,
242
- },
243
-
244
- // CSS selectors
245
- "data-panel": "",
246
- "data-panel-collapsible": collapsible || undefined,
247
- "data-panel-group-id": groupId,
248
- "data-panel-id": panelId,
249
- "data-panel-size": parseFloat("" + style.flexGrow).toFixed(1),
250
- });
251
- }
252
-
253
- export const Panel = forwardRef<ImperativePanelHandle, PanelProps>(
254
- (props: PanelProps, ref: ForwardedRef<ImperativePanelHandle>) =>
255
- createElement(PanelWithForwardedRef, { ...props, forwardedRef: ref })
256
- );
257
-
258
- PanelWithForwardedRef.displayName = "Panel";
259
- Panel.displayName = "forwardRef(Panel)";
@@ -1,443 +0,0 @@
1
- // @ts-expect-error This is an experimental API
2
- // eslint-disable-next-line no-restricted-imports
3
- import { unstable_Activity as Activity, Fragment } from "react";
4
- import { Root, createRoot } from "react-dom/client";
5
- import { act } from "react-dom/test-utils";
6
- import {
7
- ImperativePanelGroupHandle,
8
- ImperativePanelHandle,
9
- Panel,
10
- PanelGroup,
11
- PanelResizeHandle,
12
- getPanelElement,
13
- } from ".";
14
- import { assert } from "./utils/assert";
15
- import { getPanelGroupElement } from "./utils/dom/getPanelGroupElement";
16
- import {
17
- mockPanelGroupOffsetWidthAndHeight,
18
- verifyAttribute,
19
- } from "./utils/test-utils";
20
- import { createRef } from "./vendor/react";
21
-
22
- describe("PanelGroup", () => {
23
- let expectedWarnings: string[] = [];
24
- let root: Root;
25
- let container: HTMLElement;
26
- let uninstallMockOffsetWidthAndHeight: () => void;
27
-
28
- function expectWarning(expectedMessage: string) {
29
- expectedWarnings.push(expectedMessage);
30
- }
31
-
32
- beforeEach(() => {
33
- // @ts-expect-error
34
- global.IS_REACT_ACT_ENVIRONMENT = true;
35
-
36
- // JSDom doesn't support element sizes
37
- uninstallMockOffsetWidthAndHeight = mockPanelGroupOffsetWidthAndHeight();
38
-
39
- container = document.createElement("div");
40
- document.body.appendChild(container);
41
-
42
- expectedWarnings = [];
43
- root = createRoot(container);
44
-
45
- jest.spyOn(console, "warn").mockImplementation((actualMessage: string) => {
46
- const match = expectedWarnings.findIndex((expectedMessage) => {
47
- return actualMessage.includes(expectedMessage);
48
- });
49
-
50
- if (match >= 0) {
51
- expectedWarnings.splice(match, 1);
52
- return;
53
- }
54
-
55
- throw Error(`Unexpected warning: ${actualMessage}`);
56
- });
57
- });
58
-
59
- afterEach(() => {
60
- uninstallMockOffsetWidthAndHeight();
61
-
62
- jest.clearAllMocks();
63
- jest.resetModules();
64
-
65
- act(() => {
66
- root.unmount();
67
- });
68
-
69
- expect(expectedWarnings).toHaveLength(0);
70
- });
71
-
72
- it("should recalculate layout after being hidden by Activity", () => {
73
- const panelRef = createRef<ImperativePanelHandle>();
74
-
75
- let mostRecentLayout: number[] | null = null;
76
-
77
- const onLayout = (layout: number[]) => {
78
- mostRecentLayout = layout;
79
- };
80
-
81
- act(() => {
82
- root.render(
83
- <Activity mode="visible">
84
- <PanelGroup direction="horizontal" onLayout={onLayout}>
85
- <Panel id="left" ref={panelRef} />
86
- <PanelResizeHandle />
87
- <Panel defaultSize={40} id="right" />
88
- </PanelGroup>
89
- </Activity>
90
- );
91
- });
92
-
93
- expect(mostRecentLayout).toEqual([60, 40]);
94
- expect(panelRef.current?.getSize()).toEqual(60);
95
-
96
- const leftPanelElement = getPanelElement("left");
97
- const rightPanelElement = getPanelElement("right");
98
- expect(leftPanelElement?.getAttribute("data-panel-size")).toBe("60.0");
99
- expect(rightPanelElement?.getAttribute("data-panel-size")).toBe("40.0");
100
-
101
- act(() => {
102
- root.render(
103
- <Activity mode="hidden">
104
- <PanelGroup direction="horizontal" onLayout={onLayout}>
105
- <Panel id="left" ref={panelRef} />
106
- <PanelResizeHandle />
107
- <Panel defaultSize={40} id="right" />
108
- </PanelGroup>
109
- </Activity>
110
- );
111
- });
112
-
113
- act(() => {
114
- root.render(
115
- <Activity mode="visible">
116
- <PanelGroup direction="horizontal" onLayout={onLayout}>
117
- <Panel id="left" ref={panelRef} />
118
- <PanelResizeHandle />
119
- <Panel defaultSize={40} id="right" />
120
- </PanelGroup>
121
- </Activity>
122
- );
123
- });
124
-
125
- expect(mostRecentLayout).toEqual([60, 40]);
126
- expect(panelRef.current?.getSize()).toEqual(60);
127
-
128
- // This bug is only observable in the DOM; callbacks will not re-fire
129
- expect(leftPanelElement?.getAttribute("data-panel-size")).toBe("60.0");
130
- expect(rightPanelElement?.getAttribute("data-panel-size")).toBe("40.0");
131
- });
132
-
133
- // github.com/bvaughn/react-resizable-panels/issues/303
134
- it("should recalculate layout after panels are changed", () => {
135
- let mostRecentLayout: number[] | null = null;
136
-
137
- const onLayout = (layout: number[]) => {
138
- mostRecentLayout = layout;
139
- };
140
-
141
- act(() => {
142
- root.render(
143
- <PanelGroup direction="vertical" onLayout={onLayout}>
144
- <Panel id="foo" minSize={30} order={0} />
145
- <PanelResizeHandle />
146
- <Panel id="bar" minSize={70} order={1} />
147
- </PanelGroup>
148
- );
149
- });
150
- expect(mostRecentLayout).toEqual([30, 70]);
151
-
152
- act(() => {
153
- root.render(
154
- <PanelGroup direction="vertical" onLayout={onLayout}>
155
- <Panel id="bar" minSize={70} order={0} />
156
- </PanelGroup>
157
- );
158
- });
159
- expect(mostRecentLayout).toEqual([100]);
160
- });
161
-
162
- describe("imperative handle API", () => {
163
- it("should report the most recently rendered group id", () => {
164
- const ref = createRef<ImperativePanelGroupHandle>();
165
-
166
- act(() => {
167
- root.render(<PanelGroup direction="horizontal" id="one" ref={ref} />);
168
- });
169
-
170
- expect(ref.current?.getId()).toBe("one");
171
-
172
- act(() => {
173
- root.render(<PanelGroup direction="horizontal" id="two" ref={ref} />);
174
- });
175
-
176
- expect(ref.current?.getId()).toBe("two");
177
- });
178
-
179
- it("should get and set layouts", () => {
180
- const ref = createRef<ImperativePanelGroupHandle>();
181
-
182
- let mostRecentLayout: number[] | null = null;
183
-
184
- const onLayout = (layout: number[]) => {
185
- mostRecentLayout = layout;
186
- };
187
-
188
- act(() => {
189
- root.render(
190
- <PanelGroup direction="horizontal" onLayout={onLayout} ref={ref}>
191
- <Panel defaultSize={50} id="a" />
192
- <PanelResizeHandle />
193
- <Panel defaultSize={50} id="b" />
194
- </PanelGroup>
195
- );
196
- });
197
-
198
- expect(mostRecentLayout).toEqual([50, 50]);
199
-
200
- act(() => {
201
- ref.current?.setLayout([25, 75]);
202
- });
203
-
204
- expect(mostRecentLayout).toEqual([25, 75]);
205
- });
206
- });
207
-
208
- it("should support ...rest attributes", () => {
209
- act(() => {
210
- root.render(
211
- <PanelGroup
212
- data-test-name="foo"
213
- direction="horizontal"
214
- id="group"
215
- tabIndex={123}
216
- title="bar"
217
- >
218
- <Panel />
219
- <PanelResizeHandle />
220
- <Panel />
221
- </PanelGroup>
222
- );
223
- });
224
-
225
- const element = getPanelGroupElement("group", container);
226
- assert(element, "");
227
- expect(element.tabIndex).toBe(123);
228
- expect(element.getAttribute("data-test-name")).toBe("foo");
229
- expect(element.title).toBe("bar");
230
- });
231
-
232
- describe("callbacks", () => {
233
- describe("onLayout", () => {
234
- it("should be called with the initial group layout on mount", () => {
235
- let onLayout = jest.fn();
236
-
237
- act(() => {
238
- root.render(
239
- <PanelGroup direction="horizontal" onLayout={onLayout}>
240
- <Panel defaultSize={35} />
241
- <PanelResizeHandle />
242
- <Panel defaultSize={65} />
243
- </PanelGroup>
244
- );
245
- });
246
-
247
- expect(onLayout).toHaveBeenCalledTimes(1);
248
- expect(onLayout).toHaveBeenCalledWith([35, 65]);
249
- });
250
-
251
- it("should be called any time the group layout changes", () => {
252
- let onLayout = jest.fn();
253
- let panelGroupRef = createRef<ImperativePanelGroupHandle>();
254
- let panelRef = createRef<ImperativePanelHandle>();
255
-
256
- act(() => {
257
- root.render(
258
- <PanelGroup
259
- direction="horizontal"
260
- onLayout={onLayout}
261
- ref={panelGroupRef}
262
- >
263
- <Panel defaultSize={35} ref={panelRef} />
264
- <PanelResizeHandle />
265
- <Panel defaultSize={65} />
266
- </PanelGroup>
267
- );
268
- });
269
-
270
- onLayout.mockReset();
271
-
272
- act(() => {
273
- panelGroupRef.current?.setLayout([25, 75]);
274
- });
275
-
276
- expect(onLayout).toHaveBeenCalledTimes(1);
277
- expect(onLayout).toHaveBeenCalledWith([25, 75]);
278
-
279
- onLayout.mockReset();
280
-
281
- act(() => {
282
- panelRef.current?.resize(50);
283
- });
284
-
285
- expect(onLayout).toHaveBeenCalledTimes(1);
286
- expect(onLayout).toHaveBeenCalledWith([50, 50]);
287
- });
288
- });
289
- });
290
-
291
- describe("data attributes", () => {
292
- it("should initialize with the correct props based attributes", () => {
293
- act(() => {
294
- root.render(
295
- <PanelGroup direction="horizontal" id="test-group"></PanelGroup>
296
- );
297
- });
298
-
299
- const element = getPanelGroupElement("test-group", container);
300
- assert(element, "");
301
-
302
- verifyAttribute(element, "data-panel-group", "");
303
- verifyAttribute(element, "data-panel-group-direction", "horizontal");
304
- verifyAttribute(element, "data-panel-group-id", "test-group");
305
- });
306
- });
307
-
308
- describe("a11y", () => {
309
- it("should pass explicit id prop to DOM", () => {
310
- act(() => {
311
- root.render(
312
- <PanelGroup direction="horizontal" id="explicit-id">
313
- <Panel />
314
- <PanelResizeHandle />
315
- <Panel />
316
- </PanelGroup>
317
- );
318
- });
319
-
320
- const element = container.querySelector("[data-panel-group]");
321
-
322
- expect(element).not.toBeNull();
323
- expect(element?.getAttribute("id")).toBe("explicit-id");
324
- });
325
-
326
- it("should not pass auto-generated id prop to DOM", () => {
327
- act(() => {
328
- root.render(
329
- <PanelGroup direction="horizontal">
330
- <Panel />
331
- <PanelResizeHandle />
332
- <Panel />
333
- </PanelGroup>
334
- );
335
- });
336
-
337
- const element = container.querySelector("[data-panel-group]");
338
-
339
- expect(element).not.toBeNull();
340
- expect(element?.getAttribute("id")).toBeNull();
341
- });
342
- });
343
-
344
- describe("DEV warnings", () => {
345
- it("should warn about unstable layouts without id and order props", () => {
346
- act(() => {
347
- root.render(
348
- <PanelGroup direction="horizontal">
349
- <Panel defaultSize={100} id="a" />
350
- </PanelGroup>
351
- );
352
- });
353
-
354
- expectWarning(
355
- "Panel id and order props recommended when panels are dynamically rendered"
356
- );
357
-
358
- act(() => {
359
- root.render(
360
- <PanelGroup direction="horizontal">
361
- <Panel defaultSize={50} id="a" />
362
- <PanelResizeHandle />
363
- <Panel defaultSize={50} id="b" />
364
- </PanelGroup>
365
- );
366
- });
367
- });
368
-
369
- it("should warn about missing resize handles", () => {
370
- expectWarning(
371
- 'Missing resize handle for PanelGroup "group-without-handle"'
372
- );
373
-
374
- act(() => {
375
- root.render(
376
- <PanelGroup direction="horizontal" id="group-without-handle">
377
- <Panel />
378
- <Panel />
379
- </PanelGroup>
380
- );
381
- });
382
- });
383
-
384
- it("should warn about an invalid declarative layout", () => {
385
- expectWarning("Invalid layout total size: 60%, 80%");
386
-
387
- act(() => {
388
- root.render(
389
- <PanelGroup direction="horizontal" id="group-without-handle">
390
- <Panel defaultSize={60} />
391
- <PanelResizeHandle />
392
- <Panel defaultSize={80} />
393
- </PanelGroup>
394
- );
395
- });
396
- });
397
-
398
- it("should warn about an invalid layout set via the imperative api", () => {
399
- const ref = createRef<ImperativePanelGroupHandle>();
400
-
401
- act(() => {
402
- root.render(
403
- <PanelGroup
404
- direction="horizontal"
405
- id="group-without-handle"
406
- ref={ref}
407
- >
408
- <Panel defaultSize={30} />
409
- <PanelResizeHandle />
410
- <Panel defaultSize={70} />
411
- </PanelGroup>
412
- );
413
- });
414
-
415
- expectWarning("Invalid layout total size: 60%, 80%");
416
-
417
- act(() => {
418
- ref.current?.setLayout([60, 80]);
419
- });
420
- });
421
-
422
- it("should warn about an empty layout", () => {
423
- act(() => {
424
- root.render(
425
- <PanelGroup direction="horizontal" id="group-without-handle">
426
- <Panel />
427
- </PanelGroup>
428
- );
429
- });
430
-
431
- // Since the layout is empty, no warning is expected (even though the sizes won't total 100%)
432
-
433
- act(() => {
434
- root.render(
435
- <PanelGroup
436
- direction="horizontal"
437
- id="group-without-handle"
438
- ></PanelGroup>
439
- );
440
- });
441
- });
442
- });
443
- });