Skip to content

Commit 841ae12

Browse files
committed
feat: track isDragging in app state
1 parent 4954cbb commit 841ae12

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

apps/demo/app/custom-ui/[...puckPath]/client.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ const Tabs = ({
6868
currentTabRef.current = currentTab;
6969
}, [currentTab]);
7070

71+
useEffect(() => {
72+
if (appState.ui.isDragging && currentTab === 1) {
73+
setCurrentTab(-1);
74+
}
75+
}, [currentTab, appState.ui.isDragging]);
76+
7177
return (
7278
<div
7379
onClick={(e) => e.stopPropagation()}

packages/core/components/Puck/context.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const defaultAppState: AppState = {
1313
arrayState: {},
1414
itemSelector: null,
1515
componentList: {},
16+
isDragging: false,
1617
},
1718
};
1819

packages/core/components/Puck/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,11 @@ export function Puck({
300300
onBeforeDragStart={(start) => {
301301
onDragStartOrUpdate(start);
302302
setItemSelector(null);
303+
dispatch({ type: "setUi", ui: { isDragging: true } });
303304
}}
304305
onDragEnd={(droppedItem) => {
305306
setDraggedItem(undefined);
307+
dispatch({ type: "setUi", ui: { isDragging: false } });
306308

307309
// User cancel drag
308310
if (!droppedItem.destination) {

packages/core/types/Config.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ export type UiState = {
261261
expanded?: boolean;
262262
}
263263
>;
264+
isDragging: boolean;
264265
};
265266

266267
export type AppState = { data: Data; ui: UiState };

0 commit comments

Comments
 (0)