Skip to content

Commit a4df0d9

Browse files
committed
Bug with restrictRect and resizable
1 parent 2138dd1 commit a4df0d9

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

packages/@interactjs/modifiers/restrict/pointer.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function start ({ rect, startOffset, state, interaction, pageCoords }: ModifierA
6565
state.offset = offset
6666
}
6767

68-
function set ({ coords, interaction, state }: ModifierArg<RestrictState>) {
68+
function set ({ coords, interaction, state, edges }: ModifierArg<RestrictState>) {
6969
const { options, offset } = state
7070

7171
const restriction = getRestrictionRect(options.restriction, interaction, coords)
@@ -74,8 +74,43 @@ function set ({ coords, interaction, state }: ModifierArg<RestrictState>) {
7474

7575
const rect = rectUtils.xywhToTlbr(restriction)
7676

77-
coords.x = Math.max(Math.min(rect.right - offset.right, coords.x), rect.left + offset.left)
78-
coords.y = Math.max(Math.min(rect.bottom - offset.bottom, coords.y), rect.top + offset.top)
77+
// Configure coords X
78+
switch (true) {
79+
// Drag
80+
case edges.left && edges.right:
81+
coords.x = Math.max(Math.min(rect.right - offset.right, coords.x), rect.left + offset.left)
82+
break
83+
// Resize
84+
case edges.left:
85+
coords.x = Math.max(rect.left + offset.left, coords.x)
86+
break
87+
case edges.right:
88+
coords.x = Math.min(rect.right - offset.right, coords.x)
89+
break
90+
// Other
91+
default:
92+
coords.x = Math.max(Math.min(rect.right - offset.right, coords.x), rect.left + offset.left)
93+
break
94+
}
95+
96+
// Configure coords Y
97+
switch (true) {
98+
// Drag
99+
case edges.top && edges.bottom:
100+
coords.y = Math.max(Math.min(rect.bottom - offset.bottom, coords.y), rect.top + offset.top)
101+
break
102+
// Resize
103+
case edges.top:
104+
coords.y = Math.max(rect.top + offset.top, coords.y)
105+
break
106+
case edges.bottom:
107+
coords.y = Math.min(rect.bottom - offset.bottom, coords.y)
108+
break
109+
// Other
110+
default:
111+
coords.y = Math.max(Math.min(rect.bottom - offset.bottom, coords.y), rect.top + offset.top)
112+
break
113+
}
79114
}
80115

81116
export function getRestrictionRect (

0 commit comments

Comments
 (0)