Skip to content

Commit f99edde

Browse files
raunofreibergeps1lon
authored andcommitted
[dev-overlay] Consider scrollbar width for drag positioning (#78865)
This PR fixes a small bug with the dragging logic established in #78716 Namely, I didn't take into account the scrollbar width when calculating `translate` for each corner. So if the page was scrollable the drag end would be a bit janky: https://github.com/user-attachments/assets/17e227e9-7af1-4ab8-91b2-b7cc4d363793 After this PR, the snapping is much smoother with no jank: https://github.com/user-attachments/assets/06021fae-da61-46b3-b224-11f319835fa3
1 parent 8312f8a commit f99edde

File tree

1 file changed

+17
-3
lines changed
  • packages/next/src/client/components/react-dev-overlay/ui/components/errors/dev-tools-indicator

1 file changed

+17
-3
lines changed

packages/next/src/client/components/react-dev-overlay/ui/components/errors/dev-tools-indicator/draggable.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,17 @@ export function Draggable({
7373
const offset = padding * 2
7474
const triggerWidth = ref.current?.offsetWidth || 0
7575
const triggerHeight = ref.current?.offsetHeight || 0
76+
const scrollbarWidth =
77+
window.innerWidth - document.documentElement.clientWidth
7678

7779
function getAbsolutePosition(corner: Corners) {
7880
const isRight = corner.includes('right')
7981
const isBottom = corner.includes('bottom')
8082

8183
return {
82-
x: isRight ? window.innerWidth - offset - triggerWidth : 0,
84+
x: isRight
85+
? window.innerWidth - scrollbarWidth - offset - triggerWidth
86+
: 0,
8387
y: isBottom ? window.innerHeight - offset - triggerHeight : 0,
8488
}
8589
}
@@ -93,15 +97,25 @@ export function Draggable({
9397
y: 0 - basePosition.y,
9498
},
9599
'top-right': {
96-
x: window.innerWidth - offset - triggerWidth - basePosition.x,
100+
x:
101+
window.innerWidth -
102+
scrollbarWidth -
103+
offset -
104+
triggerWidth -
105+
basePosition.x,
97106
y: 0 - basePosition.y,
98107
},
99108
'bottom-left': {
100109
x: 0 - basePosition.x,
101110
y: window.innerHeight - offset - triggerHeight - basePosition.y,
102111
},
103112
'bottom-right': {
104-
x: window.innerWidth - offset - triggerWidth - basePosition.x,
113+
x:
114+
window.innerWidth -
115+
scrollbarWidth -
116+
offset -
117+
triggerWidth -
118+
basePosition.x,
105119
y: window.innerHeight - offset - triggerHeight - basePosition.y,
106120
},
107121
}

0 commit comments

Comments
 (0)