Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with restrictRect and resizable #947

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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