Skip to content

Commit

Permalink
Bug with restrictRect and resizable
Browse files Browse the repository at this point in the history
  • Loading branch information
tups committed Apr 8, 2022
1 parent 2138dd1 commit a4df0d9
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions packages/@interactjs/modifiers/restrict/pointer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function start ({ rect, startOffset, state, interaction, pageCoords }: ModifierA
state.offset = offset
}

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

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

const rect = rectUtils.xywhToTlbr(restriction)

coords.x = Math.max(Math.min(rect.right - offset.right, coords.x), rect.left + offset.left)
coords.y = Math.max(Math.min(rect.bottom - offset.bottom, coords.y), rect.top + offset.top)
// Configure coords X
switch (true) {
// Drag
case edges.left && edges.right:
coords.x = Math.max(Math.min(rect.right - offset.right, coords.x), rect.left + offset.left)
break
// Resize
case edges.left:
coords.x = Math.max(rect.left + offset.left, coords.x)
break
case edges.right:
coords.x = Math.min(rect.right - offset.right, coords.x)
break
// Other
default:
coords.x = Math.max(Math.min(rect.right - offset.right, coords.x), rect.left + offset.left)
break
}

// Configure coords Y
switch (true) {
// Drag
case edges.top && edges.bottom:
coords.y = Math.max(Math.min(rect.bottom - offset.bottom, coords.y), rect.top + offset.top)
break
// Resize
case edges.top:
coords.y = Math.max(rect.top + offset.top, coords.y)
break
case edges.bottom:
coords.y = Math.min(rect.bottom - offset.bottom, coords.y)
break
// Other
default:
coords.y = Math.max(Math.min(rect.bottom - offset.bottom, coords.y), rect.top + offset.top)
break
}
}

export function getRestrictionRect (
Expand Down

0 comments on commit a4df0d9

Please sign in to comment.