Skip to content

limit item dragging between groups (improve moveResizeValidator via dragGroupDelta)#787

Open
Dexmaster wants to merge 1 commit intonamespace-ee:mainfrom
Dexmaster:limit-group-movement
Open

limit item dragging between groups (improve moveResizeValidator via dragGroupDelta)#787
Dexmaster wants to merge 1 commit intonamespace-ee:mainfrom
Dexmaster:limit-group-movement

Conversation

@Dexmaster
Copy link

@Dexmaster Dexmaster commented Nov 2, 2020

Issue Number 514

The closest issue I could find is #514
moveResizeValidator for dragging should be able to return time and groupDelta to block drag to specific group.

Overview of PR

Two more arguments added to moveResizeValidator:

  • dragOrderIndex (original group index of item)
  • dragGroupDelta (group shift difference on dragging)

Now moveResizeValidator can return either:

  • timestamp in ms (integer) as before
  • object with dragTime timestamp in ms (integer) and dragGroupDelta final group index shift (integer) new

Added small demo with even/odd movement validation (item from even row can be moved to only even row and vice versa)

@Dexmaster Dexmaster changed the title improve moveResizeValidator via dragGroupDelta limit item dragging between groups (improve moveResizeValidator via dragGroupDelta) Nov 2, 2020
Copy link

@arenac arenac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change covered by tests?

@lnagel
Copy link
Member

lnagel commented Feb 5, 2026

@developer-ocansey — Flagging this for your review.

Recommendation: Worth porting to the current TypeScript codebase

What it does

Extends moveResizeValidator to accept two additional arguments (dragOrderIndex and dragGroupDelta) and return either a number (backward-compatible) or an object { dragTime, dragGroupDelta }, allowing consumers to constrain both time and group during drag operations.

Why it's valuable

The ability to constrain item dragging to specific groups is a real scheduling requirement (e.g., "items from even rows can only move to even rows"). The current moveResizeValidator only returns a time value with no way to control the group. This PR's approach is backward-compatible — if the validator returns a number, it works as before; if it returns an object, both dragTime and dragGroupDelta are applied.

The implementation is clean:

  • New validateDragState method extracts and centralizes validation logic
  • Type checking handles both return types (typeof result === 'number' vs 'object')
  • The demo clearly illustrates a checker-pattern movement constraint
  • A reviewer asked about test coverage — no tests were included, so those would need to be added

What needs adaptation

The PR targets the old Item.js, now Item.tsx. The current moveResizeValidator TypeScript type is:

moveResizeValidator?: (action: 'move' | 'resize', item: TimelineItemBase<any>, time: number, resizeEdge?: ResizeEdge | null) => number

This would need to be extended to accept the additional params and support the union return type. The validateDragState method should be added to the current Item.tsx (the drag handler structure with interact.js is still the same).

Effort estimate

Medium — focused changes to Item.tsx and its type definitions. The interact.js drag handler call sites at lines ~336 and ~357 would need the same enhancement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants