Skip to content

Conversation

@DhyaniKavya
Copy link
Contributor

isssue : #5361

Problem:
In the Music Blocks editor, the collapse/expand arrow on Note blocks behaves unreliably.
Clicking the arrow sometimes initiates a drag action instead of toggling the collapsed state, causing the Note block to detach from its parent (e.g., Start or Set Instrument block).

This makes collapsing/expanding notes frustrating and unpredictable for users.

Root Cause:
The issue was caused by conflicting event handlers in block.js:
-mousedown correctly detects clicks on the collapse/expand arrow, but does not prevent drag initialization
-pressmove always starts dragging on even tiny mouse movements
->As a result, small pointer movement between mousedown and click triggers drag before the collapse action can occur

Solution:
This PR introduces a small but robust fix to clearly separate collapse intent from drag intent:
-Track when the collapse/expand arrow is clicked using a dedicated flag
-Prevent drag logic from running when the interaction starts on the arrow
-Reset the flag safely on pressup and mouseout events

This ensures:
->Clicking the arrow always toggles collapse/expand
->Dragging only occurs when interacting with the block body
->No regression to normal drag behavior

Testing Performed:
Manual testing in browser:
-Created a project with a Start block and a nested Note block
-Clicked the collapse/expand arrow rapidly multiple times

Block toggles correctly every time
Block never detaches from parent
Dragged the Note block from its body (not the arrow)
Drag behavior works as expected

Visual Proof:
-Before: Clicking the collapse arrow sometimes drags the block out
-After: Collapse/expand works reliably with no accidental dragging
(Attached before/after screenshots for reference)

Files Changed:
->block.js

Notes:

after before This change improves usability without altering existing drag mechanics and follows the current event-handling structure of the project.

I’m happy to make adjustments if maintainers prefer a different approach.

- Add isCollapseButtonClick flag to prevent drag when clicking collapse/expand buttons
- Guard pressmove handler to skip drag logic when flag is set
- Reset flag on pressup and mouseout events
- Add event.stopPropagation() to prevent event bubbling

This ensures that clicking the collapse/expand arrow always toggles the block state
without triggering drag behavior, while preserving normal drag functionality from
the block body.
@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@DhyaniKavya
Copy link
Contributor Author

@walterbender please review

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.

1 participant