Commit ce1f005
fix(context-menu): prevent right-click release from selecting menu items (tldraw#8499)
When right-clicking to open a context menu and moving the mouse quickly,
the `pointerup` (button 2) from the right-click can land on a menu item
and trigger selection without the user intending to click it.
Closes tldraw#8480
**Root cause:** Radix's `MenuItem` calls `event.currentTarget.click()`
on `pointerup` when `isPointerDownRef` is false (i.e. the pointer wasn't
pressed down on that item). This is intentional for drag-to-select
behavior, but it doesn't check the pointer button — so a right-click
release (button 2) triggers the same path as a left-click release.
**Fix:** Add an `onPointerUp` handler to `_ContextMenu.Item` that calls
`preventDefault()` for non-left-click buttons. Radix's
`composeEventHandlers` runs the user handler first and skips its
internal handler when `defaultPrevented` is true, so the synthetic
`click()` never fires.
### Change type
- [x] `bugfix`
### Test plan
1. Right-click on empty canvas — context menu appears
2. Move mouse quickly across menu items — no item should activate
3. Right-click on a shape, move fast across items — no item should
activate
4. Left-click a menu item normally — should still work
5. Drag from outside the menu onto an item and release (left button) —
should still select
- [ ] Unit tests
- [ ] End to end tests
### Release notes
- Fix context menu items being accidentally selected when right-clicking
and quickly moving the mouse.
### Code changes
| Section | LOC change |
| ---------- | ---------- |
| Core code | +9 / -0 |
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent f9d0210 commit ce1f005
1 file changed
Lines changed: 9 additions & 0 deletions
File tree
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
152 | 161 | | |
153 | 162 | | |
154 | 163 | | |
| |||
0 commit comments