Skip to content

Conversation

@willeastcott
Copy link
Contributor

@willeastcott willeastcott commented Jan 18, 2026

Fixes #382

Summary

  • Migrate TreeView and TreeViewItem from mouse events to pointer events for unified handling of mouse, touch, and pen input
  • Add touch/pen drag-and-drop support with proper hit-testing via elementFromPoint()
  • Add CSS touch-action: none to prevent browser gesture interference during drag operations
  • Add CSS pointer-events: none to drag handle to prevent interference with hit-testing

Details

Pointer Events Migration

All mouse events have been migrated to their pointer event equivalents:

  • mousedownpointerdown
  • mouseuppointerup
  • mousemovepointermove
  • mouseoverpointerover
  • mouseleavepointerleave

Touch/Pen Drag Support

Touch and pen inputs require special handling because:

  1. The dragstart DOM event doesn't fire reliably on touch devices
  2. pointerover events don't fire during touch drag (the pointer stays "attached" to the original element)

To address this:

  • Drag is initiated from pointerdown for non-mouse pointer types (evt.pointerType !== 'mouse')
  • During drag, pointermove uses document.elementFromPoint() to detect which TreeViewItem is under the touch point
  • The pointermove listener is now always active during drag operations (not just for scrollable TreeViews)

CSS Changes

  • touch-action: none on .pcui-treeview-item-contents prevents the browser from cancelling pointer events to handle its own touch gestures
  • pointer-events: none on .pcui-treeview-drag-handle prevents the drag indicator from interfering with elementFromPoint() hit-testing

@willeastcott willeastcott requested a review from Copilot January 18, 2026 03:38
@willeastcott willeastcott self-assigned this Jan 18, 2026
@willeastcott willeastcott added the enhancement New feature or request label Jan 18, 2026
Copy link
Contributor

Copilot AI left a 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 pointerdown events since dragstart doesn't fire reliably for non-mouse inputs
  • Added hit-testing via elementFromPoint() during pointermove for touch/pen drag-over detection (since pointerover doesn't fire during touch drag)
  • Added CSS properties (touch-action: none and pointer-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.

Copy link
Contributor

Copilot AI left a 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.

Copy link
Contributor

Copilot AI left a 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.

Comment on lines 820 to 821
const item = (contentsElement.parentElement as any)?.ui as TreeViewItem;
if (item && item instanceof TreeViewItem) {
Copy link

Copilot AI Jan 18, 2026

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.

Suggested change
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;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tree view drag n drop (reparent, move, drag) on touch devices.

3 participants