From 65a8e7afb3f3d675bc35e71855ee1757a0a10750 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Mon, 13 Nov 2023 13:52:25 -0500 Subject: [PATCH] Fix bad dev-conditionally around data attributes --- packages/react-resizable-panels/src/Panel.ts | 2 +- .../react-resizable-panels/src/PanelGroup.ts | 10 +++++--- .../src/PanelResizeHandle.ts | 25 +++++++++---------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/packages/react-resizable-panels/src/Panel.ts b/packages/react-resizable-panels/src/Panel.ts index 451e00ae3..e94d9d84f 100644 --- a/packages/react-resizable-panels/src/Panel.ts +++ b/packages/react-resizable-panels/src/Panel.ts @@ -243,12 +243,12 @@ export function PanelWithForwardedRef({ // CSS selectors "data-panel": "", + "data-panel-id": panelId, // e2e test attributes "data-panel-collapsible": isDevelopment ? collapsible || undefined : undefined, - "data-panel-id": isDevelopment ? panelId : undefined, "data-panel-size": isDevelopment ? parseFloat("" + style.flexGrow).toFixed(1) : undefined, diff --git a/packages/react-resizable-panels/src/PanelGroup.ts b/packages/react-resizable-panels/src/PanelGroup.ts index 5c6bd5ca6..7b2fec053 100644 --- a/packages/react-resizable-panels/src/PanelGroup.ts +++ b/packages/react-resizable-panels/src/PanelGroup.ts @@ -266,6 +266,10 @@ function PanelGroupWithForwardedRef({ } const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId); + if (groupSizePixels <= 0) { + // Wait until the group has rendered a non-zero size before computing layout. + return; + } if (unsafeLayout == null) { unsafeLayout = calculateUnsafeDefaultLayout({ @@ -925,10 +929,8 @@ function PanelGroupWithForwardedRef({ // CSS selectors "data-panel-group": "", - - // e2e test attributes - "data-panel-group-direction": isDevelopment ? direction : undefined, - "data-panel-group-id": isDevelopment ? groupId : undefined, + "data-panel-group-direction": direction, + "data-panel-group-id": groupId, }) ); } diff --git a/packages/react-resizable-panels/src/PanelResizeHandle.ts b/packages/react-resizable-panels/src/PanelResizeHandle.ts index 5fe9b5ee0..7173967f7 100644 --- a/packages/react-resizable-panels/src/PanelResizeHandle.ts +++ b/packages/react-resizable-panels/src/PanelResizeHandle.ts @@ -151,19 +151,6 @@ export function PanelResizeHandle({ return createElement(Type, { children, className: classNameFromProps, - - // CSS selectors - "data-resize-handle": "", - - "data-resize-handle-active": isDragging - ? "pointer" - : isFocused - ? "keyboard" - : undefined, - "data-panel-group-direction": direction, - "data-panel-group-id": groupId, - "data-panel-resize-handle-enabled": !disabled, - "data-panel-resize-handle-id": resizeHandleId, onBlur: () => setIsFocused(false), onFocus: () => setIsFocused(true), onMouseDown: (event: ReactMouseEvent) => { @@ -192,6 +179,18 @@ export function PanelResizeHandle({ ...styleFromProps, }, tabIndex: 0, + + // CSS selectors + "data-panel-group-direction": direction, + "data-panel-group-id": groupId, + "data-resize-handle": "", + "data-resize-handle-active": isDragging + ? "pointer" + : isFocused + ? "keyboard" + : undefined, + "data-panel-resize-handle-enabled": !disabled, + "data-panel-resize-handle-id": resizeHandleId, }); }