Skip to content

Commit 5c4bd90

Browse files
committed
[devtools] proper draggable for header and footer only
1 parent 76c64ec commit 5c4bd90

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

packages/next/src/next-devtools/dev-overlay/components/devtools-panel/devtools-panel-footer.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ export const DEVTOOLS_PANEL_FOOTER_STYLES = css`
5151
align-items: center;
5252
border-top: 1px solid var(--color-gray-400);
5353
border-radius: 0 0 var(--rounded-xl) var(--rounded-xl);
54+
55+
/* For draggable */
56+
cursor: move;
57+
user-select: none;
58+
59+
/* Reset for children */
60+
& * {
61+
cursor: auto;
62+
/* user-select: auto; seems to not restore properly */
63+
user-select: text;
64+
}
5465
}
5566
5667
[data-nextjs-devtools-panel-footer-tab-group] {

packages/next/src/next-devtools/dev-overlay/components/devtools-panel/devtools-panel.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export function DevToolsPanel({
8787
devToolsPosition: p,
8888
})
8989
}}
90+
dragHandleSelector="[data-nextjs-devtools-panel-header], [data-nextjs-devtools-panel-footer]"
9091
>
9192
<>
9293
<Dialog
@@ -267,6 +268,16 @@ export const DEVTOOLS_PANEL_STYLES = css`
267268
justify-content: space-between;
268269
align-items: center;
269270
border-bottom: 1px solid var(--color-gray-400);
271+
272+
/* For draggable */
273+
cursor: move;
274+
user-select: none;
275+
/* Reset for children */
276+
& * {
277+
cursor: auto;
278+
/* user-select: auto; seems to not restore properly */
279+
user-select: text;
280+
}
270281
}
271282
272283
[data-nextjs-devtools-panel-header-tab-group] {
@@ -324,7 +335,7 @@ export const DEVTOOLS_PANEL_STYLES = css`
324335
[data-nextjs-devtools-panel-header-action-button] {
325336
background: transparent;
326337
border: none;
327-
cursor: pointer;
338+
cursor: pointer !important;
328339
display: flex;
329340
align-items: center;
330341
justify-content: center;

packages/next/src/next-devtools/dev-overlay/components/errors/dev-tools-indicator/draggable.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,22 @@ export function Draggable({
1717
position: currentCorner,
1818
setPosition: setCurrentCorner,
1919
onDragStart,
20+
dragHandleSelector,
2021
...props
2122
}: {
2223
children: React.ReactElement
2324
position: Corners
2425
padding: number
2526
setPosition: (position: Corners) => void
2627
onDragStart?: () => void
28+
dragHandleSelector?: string
2729
}) {
2830
const { ref, animate, ...drag } = useDrag({
2931
threshold: 5,
3032
onDragStart,
3133
onDragEnd,
3234
onAnimationEnd,
35+
dragHandleSelector,
3336
})
3437

3538
function onDragEnd(translation: Point, velocity: Point) {
@@ -134,6 +137,7 @@ interface UseDragOptions {
134137
onDragEnd?: (translation: Point, velocity: Point) => void
135138
onAnimationEnd?: (corner: Corner) => void
136139
threshold: number // Minimum movement before drag starts
140+
dragHandleSelector?: string
137141
}
138142

139143
interface Velocity {
@@ -185,10 +189,31 @@ export function useDrag(options: UseDragOptions) {
185189
}
186190
}
187191

192+
function isValidDragHandle(target: EventTarget | null): boolean {
193+
if (!options.dragHandleSelector || !ref.current || !target) {
194+
return true // If no selector provided, entire element is draggable
195+
}
196+
197+
const element = target as Element
198+
if (!element.matches) {
199+
return false
200+
}
201+
202+
// Check if the target element directly matches the drag handle selector
203+
// This excludes children elements, only allowing drag from the exact element
204+
return element.matches(options.dragHandleSelector)
205+
}
206+
188207
function onPointerDown(e: React.PointerEvent) {
189208
if (e.button !== 0) {
190209
return // ignore right click
191210
}
211+
212+
// Check if the pointer down event is on a valid drag handle
213+
if (!isValidDragHandle(e.target)) {
214+
return
215+
}
216+
192217
origin.current = { x: e.clientX, y: e.clientY }
193218
state.current = 'press'
194219
window.addEventListener('pointermove', onPointerMove)

0 commit comments

Comments
 (0)