Unverified Commit 04a900f7 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

[devtools] proper draggable for header and footer only (#80792)

Previously, the entire dialog was draggable, which conflicted with the
default user select. Therefore, only the header and the footer were
specified to be draggable, which does not include the children, e.g., a
button inside the header.

### Before


https://github.com/user-attachments/assets/c5867462-5cdd-486e-b84c-e6bbd47a4c34

### After


https://github.com/user-attachments/assets/4906898a-5442-4526-b0ce-e31ac86c1322

Closes NEXT-4547
parent 631e7e65
...@@ -51,6 +51,15 @@ export const DEVTOOLS_PANEL_FOOTER_STYLES = css` ...@@ -51,6 +51,15 @@ export const DEVTOOLS_PANEL_FOOTER_STYLES = css`
align-items: center; align-items: center;
border-top: 1px solid var(--color-gray-400); border-top: 1px solid var(--color-gray-400);
border-radius: 0 0 var(--rounded-xl) var(--rounded-xl); border-radius: 0 0 var(--rounded-xl) var(--rounded-xl);
/* 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-footer-tab-group] { [data-nextjs-devtools-panel-footer-tab-group] {
......
...@@ -97,6 +97,7 @@ export function DevToolsPanel({ ...@@ -97,6 +97,7 @@ export function DevToolsPanel({
devToolsPosition: p, devToolsPosition: p,
}) })
}} }}
dragHandleSelector="[data-nextjs-devtools-panel-header], [data-nextjs-devtools-panel-footer]"
> >
<> <>
<Dialog <Dialog
...@@ -257,6 +258,15 @@ export const DEVTOOLS_PANEL_STYLES = css` ...@@ -257,6 +258,15 @@ export const DEVTOOLS_PANEL_STYLES = css`
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
border-bottom: 1px solid var(--color-gray-400); 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] { [data-nextjs-devtools-panel-header-tab-group] {
......
...@@ -17,6 +17,7 @@ export function Draggable({ ...@@ -17,6 +17,7 @@ export function Draggable({
position: currentCorner, position: currentCorner,
setPosition: setCurrentCorner, setPosition: setCurrentCorner,
onDragStart, onDragStart,
dragHandleSelector,
...props ...props
}: { }: {
children: React.ReactElement children: React.ReactElement
...@@ -24,12 +25,14 @@ export function Draggable({ ...@@ -24,12 +25,14 @@ export function Draggable({
padding: number padding: number
setPosition: (position: Corners) => void setPosition: (position: Corners) => void
onDragStart?: () => void onDragStart?: () => void
dragHandleSelector?: string
}) { }) {
const { ref, animate, ...drag } = useDrag({ const { ref, animate, ...drag } = useDrag({
threshold: 5, threshold: 5,
onDragStart, onDragStart,
onDragEnd, onDragEnd,
onAnimationEnd, onAnimationEnd,
dragHandleSelector,
}) })
function onDragEnd(translation: Point, velocity: Point) { function onDragEnd(translation: Point, velocity: Point) {
...@@ -134,6 +137,7 @@ interface UseDragOptions { ...@@ -134,6 +137,7 @@ interface UseDragOptions {
onDragEnd?: (translation: Point, velocity: Point) => void onDragEnd?: (translation: Point, velocity: Point) => void
onAnimationEnd?: (corner: Corner) => void onAnimationEnd?: (corner: Corner) => void
threshold: number // Minimum movement before drag starts threshold: number // Minimum movement before drag starts
dragHandleSelector?: string
} }
interface Velocity { interface Velocity {
...@@ -185,10 +189,31 @@ export function useDrag(options: UseDragOptions) { ...@@ -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) { function onPointerDown(e: React.PointerEvent) {
if (e.button !== 0) { if (e.button !== 0) {
return // ignore right click 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 } origin.current = { x: e.clientX, y: e.clientY }
state.current = 'press' state.current = 'press'
window.addEventListener('pointermove', onPointerMove) window.addEventListener('pointermove', onPointerMove)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment