-
Notifications
You must be signed in to change notification settings - Fork 76
Migrate TreeView to pointer events #497
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR migrates the TreeView and TreeViewItem components from mouse events to pointer events to enable unified handling of mouse, touch, and pen input. The migration adds proper touch and pen support for drag-and-drop operations.
Changes:
- Replaced mouse event handlers (
mousedown,mouseup,mousemove,mouseover,mouseleave) with pointer event equivalents - Implemented touch/pen-specific drag initiation from
pointerdownevents sincedragstartdoesn't fire reliably for non-mouse inputs - Added hit-testing via
elementFromPoint()duringpointermovefor touch/pen drag-over detection (sincepointeroverdoesn't fire during touch drag) - Added CSS properties (
touch-action: noneandpointer-events: none) to prevent browser interference with touch gestures and hit-testing
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/components/TreeViewItem/index.ts | Migrated event listeners and handlers from mouse to pointer events; added touch/pen drag initiation logic in pointerdown handler |
| src/components/TreeView/index.ts | Migrated event listeners and handlers to pointer events; added touch/pen hit-testing in _onPointerMove; made pointer move listener always active during drag for touch support |
| src/components/TreeView/style.scss | Added touch-action: none to prevent browser gesture interference and pointer-events: none to drag handle for accurate hit-testing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/components/TreeView/index.ts
Outdated
| const item = (contentsElement.parentElement as any)?.ui as TreeViewItem; | ||
| if (item && item instanceof TreeViewItem) { |
Copilot
AI
Jan 18, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type assertion (contentsElement.parentElement as any)?.ui bypasses type safety and could lead to runtime errors if the ui property is missing or has an unexpected type. While the subsequent instanceof TreeViewItem check provides runtime validation, consider adding a more robust type guard or documenting the expected DOM structure more clearly to ensure this code remains maintainable.
| const item = (contentsElement.parentElement as any)?.ui as TreeViewItem; | |
| if (item && item instanceof TreeViewItem) { | |
| const parentElement = contentsElement.parentElement as HTMLElement | null; | |
| const ui = (parentElement as unknown as { ui?: unknown })?.ui; | |
| if (ui && ui instanceof TreeViewItem) { | |
| const item = ui; |
Fixes #382
Summary
elementFromPoint()touch-action: noneto prevent browser gesture interference during drag operationspointer-events: noneto drag handle to prevent interference with hit-testingDetails
Pointer Events Migration
All mouse events have been migrated to their pointer event equivalents:
mousedown→pointerdownmouseup→pointerupmousemove→pointermovemouseover→pointerovermouseleave→pointerleaveTouch/Pen Drag Support
Touch and pen inputs require special handling because:
dragstartDOM event doesn't fire reliably on touch devicespointeroverevents don't fire during touch drag (the pointer stays "attached" to the original element)To address this:
pointerdownfor non-mouse pointer types (evt.pointerType !== 'mouse')pointermoveusesdocument.elementFromPoint()to detect which TreeViewItem is under the touch pointpointermovelistener is now always active during drag operations (not just for scrollable TreeViews)CSS Changes
touch-action: noneon.pcui-treeview-item-contentsprevents the browser from cancelling pointer events to handle its own touch gesturespointer-events: noneon.pcui-treeview-drag-handleprevents the drag indicator from interfering withelementFromPoint()hit-testing