Skip to content

fix(select): allow dragging shapes that have an onClick handler#7936

Merged
steveruizok merged 6 commits intomainfrom
fix/onclick-shape-drag
Mar 10, 2026
Merged

fix(select): allow dragging shapes that have an onClick handler#7936
steveruizok merged 6 commits intomainfrom
fix/onclick-shape-drag

Conversation

@steveruizok
Copy link
Copy Markdown
Collaborator

@steveruizok steveruizok commented Feb 14, 2026

Closes #5613

When a custom shape has an onClick handler and is not yet selected, PointingShape.onEnter defers selection to pointer up (so that onClick can fire). However, if the user drags instead of clicking, the Translating state requires a selection to operate and immediately bails back to idle—making it impossible to drag unselected shapes that have an onClick handler.

This PR fixes the issue by selecting the shape in startTranslating when the shape wasn't selected on enter and there is no existing selection. This ensures that dragging works correctly while preserving the existing behavior for shapes that are already selected or part of a multi-selection.

Kapture.2026-02-15.at.00.28.55.mp4

Change type

  • bugfix

Test plan

  1. Create a custom shape with an onClick handler
  2. Make sure the shape is not selected
  3. Attempt to drag the shape — it should translate as expected
  4. Click (without dragging) — the onClick handler should still fire
  5. Multi-select shapes and drag — existing behavior should be preserved
  • Unit tests

Release notes

  • Fix dragging unselected shapes that have an onClick handler.

Note

Medium Risk
Touches the SelectTool state machine to change when selection is applied during a drag, which could subtly affect selection/translation behavior in edge cases (e.g. grouped or multi-selected shapes). Covered by a new unit test, but still impacts core interaction logic.

Overview
Fixes a selection/translation edge case where shapes with a ShapeUtil.onClick handler could not be dragged while unselected.

PointingShape.startTranslating now ensures the hit shape is selected (only when it wasn’t selected on enter and there’s no existing selection) before transitioning to translating, preserving click-to-run-onClick behavior.

Adds a regression unit test for dragging shapes with onClick, and introduces a new examples page (shape-with-onClick) demonstrating a clickable custom shape that increments a counter via ShapeUtil.onClick.

Written by Cursor Bugbot for commit c7f6206. This will update automatically on new commits. Configure here.

When a shape has an onClick handler and is not selected, PointingShape
defers selection to pointer up. But if the user drags instead, the
Translating state requires a selection and bails out to idle. Fix by
selecting the shape in startTranslating when nothing is selected.

Closes #5613
@vercel
Copy link
Copy Markdown

vercel bot commented Feb 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
examples Ready Ready Preview Mar 10, 2026 4:22pm
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
analytics Ignored Ignored Preview Mar 10, 2026 4:22pm
tldraw-docs Ignored Ignored Preview Mar 10, 2026 4:22pm
chat-template Skipped Skipped Mar 10, 2026 4:22pm
tldraw-shader Skipped Skipped Mar 10, 2026 4:22pm
workflow-template Skipped Skipped Mar 10, 2026 4:22pm

Request Review

@huppy-bot huppy-bot bot added the bugfix Bug fix label Feb 14, 2026
@steveruizok steveruizok added the maybe An idea, something to try and see label Feb 14, 2026
steveruizok and others added 2 commits February 14, 2026 23:27
Adds an example demonstrating ShapeUtil.onClick on a custom shape,
making it easy to verify that clicking increments a counter while
dragging still translates the shape correctly.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@kaneel
Copy link
Copy Markdown
Contributor

kaneel commented Feb 16, 2026

I'm observing something that looks weird, after dragging I can see the handles, trying to resize will "drag along", Is this a regression?

dragandresizewithonclick.mov

Copy link
Copy Markdown
Member

@mimecuvalo mimecuvalo left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Member

@mimecuvalo mimecuvalo left a comment

Choose a reason for hiding this comment

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

oh actually i take it back - i didn't see @kaneel found a regression - let's look at that pls!

@steveruizok
Copy link
Copy Markdown
Collaborator Author

I'm observing something that looks weird, after dragging I can see the handles, trying to resize will "drag along", Is this a regression?

dragandresizewithonclick.mov

This is just because the shape doesn't implement an onResize, unrelated to this PR. I'll make it extend baseboxutil though.

@steveruizok steveruizok dismissed mimecuvalo’s stale review February 19, 2026 15:54

stop blocking my prs bud

@kaneel kaneel self-requested a review February 19, 2026 16:27
Copy link
Copy Markdown
Contributor

@kaneel kaneel left a comment

Choose a reason for hiding this comment

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

My bad here, LGTM

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
🔵 In progress
View logs
image-pipeline-template 978e355 Mar 02 2026, 08:45 AM

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
🔵 In progress
View logs
multiplayer-template 978e355 Mar 02 2026, 08:45 AM

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
🔵 In progress
View logs
agent-template 978e355 Mar 02 2026, 08:45 AM

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Mar 2, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
agent-template 978e355 Mar 02 2026, 08:48 AM

…lder

The example declared `category: shapes/tools` but was placed at the top level,
causing the Vite build to fail with "Example category folder missing".

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@vercel vercel bot temporarily deployed to Preview – workflow-template March 10, 2026 16:20 Inactive
@vercel vercel bot temporarily deployed to Preview – chat-template March 10, 2026 16:20 Inactive
@vercel vercel bot temporarily deployed to Preview – tldraw-shader March 10, 2026 16:20 Inactive
@steveruizok steveruizok added this pull request to the merge queue Mar 10, 2026
Merged via the queue into main with commit 0561db2 Mar 10, 2026
19 of 20 checks passed
@steveruizok steveruizok deleted the fix/onclick-shape-drag branch March 10, 2026 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Bug fix maybe An idea, something to try and see

Projects

None yet

Development

Successfully merging this pull request may close these issues.

onClick handler on shape prevents PointingShape logic

3 participants