Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ export const DEVTOOLS_PANEL_FOOTER_STYLES = css`
align-items: center;
border-top: 1px solid var(--color-gray-400);
border-radius: 0 0 var(--rounded-xl) var(--rounded-xl);

/* For draggable */
cursor: move;
user-select: none;
& > * {
Comment thread
huozhi marked this conversation as resolved.
Outdated
cursor: auto;
/* user-select: auto; follows the parent (parent none -> child none), so reset the direct child to text */
user-select: text;
}
}

[data-nextjs-devtools-panel-footer-tab-group] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export function DevToolsPanel({
devToolsPosition: p,
})
}}
dragHandleSelector="[data-nextjs-devtools-panel-header], [data-nextjs-devtools-panel-footer]"
>
<>
<Dialog
Expand Down Expand Up @@ -257,6 +258,15 @@ export const DEVTOOLS_PANEL_STYLES = css`
justify-content: space-between;
align-items: center;
border-bottom: 1px solid var(--color-gray-400);

/* For draggable */
cursor: move;
user-select: none;
& > * {
cursor: auto;
/* user-select: auto; follows the parent (parent none -> child none), so reset the direct child to text */
user-select: text;
}
}

[data-nextjs-devtools-panel-header-tab-group] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@ export function Draggable({
position: currentCorner,
setPosition: setCurrentCorner,
onDragStart,
dragHandleSelector,
...props
}: {
children: React.ReactElement
position: Corners
padding: number
setPosition: (position: Corners) => void
onDragStart?: () => void
dragHandleSelector?: string
}) {
const { ref, animate, ...drag } = useDrag({
threshold: 5,
onDragStart,
onDragEnd,
onAnimationEnd,
dragHandleSelector,
})

function onDragEnd(translation: Point, velocity: Point) {
Expand Down Expand Up @@ -134,6 +137,7 @@ interface UseDragOptions {
onDragEnd?: (translation: Point, velocity: Point) => void
onAnimationEnd?: (corner: Corner) => void
threshold: number // Minimum movement before drag starts
dragHandleSelector?: string
}

interface Velocity {
Expand Down Expand Up @@ -185,10 +189,31 @@ export function useDrag(options: UseDragOptions) {
}
}

function isValidDragHandle(target: EventTarget | null): boolean {
if (!options.dragHandleSelector || !ref.current || !target) {
return true // If no selector provided, entire element is draggable
}

const element = target as Element
if (!element.matches) {
return false
}

// Check if the target element directly matches the drag handle selector
// This excludes children elements, only allowing drag from the exact element
return element.matches(options.dragHandleSelector)
}

function onPointerDown(e: React.PointerEvent) {
if (e.button !== 0) {
return // ignore right click
}

// Check if the pointer down event is on a valid drag handle
if (!isValidDragHandle(e.target)) {
return
}

origin.current = { x: e.clientX, y: e.clientY }
state.current = 'press'
window.addEventListener('pointermove', onPointerMove)
Expand Down