Skip to content

Make Drag and Drop Example work on Touch Devices #970

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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

0x0f0f0f
Copy link
Contributor

@0x0f0f0f 0x0f0f0f commented Aug 7, 2025

Close #889

Copy link

vercel bot commented Aug 7, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
example-apps ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 11, 2025 2:53pm
4 Skipped Deployments
Name Status Preview Comments Updated (UTC)
reactflow-website ⬜️ Ignored (Inspect) Visit Preview Aug 11, 2025 2:53pm
svelteflow-website ⬜️ Ignored (Inspect) Visit Preview Aug 11, 2025 2:53pm
ui-components ⬜️ Ignored (Inspect) Visit Preview Aug 11, 2025 2:53pm
xyflow-website ⬜️ Ignored (Inspect) Visit Preview Aug 11, 2025 2:53pm

@0x0f0f0f 0x0f0f0f requested a review from Copilot August 11, 2025 14:27
Copilot

This comment was marked as outdated.

@0x0f0f0f 0x0f0f0f requested a review from Copilot August 11, 2025 14:38
Copy link
Contributor

@Copilot 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 modernizes the drag and drop example to work on touch devices by replacing the HTML Drag and Drop API with pointer events. The implementation maintains the same user experience while adding touch device support.

Key changes:

  • Replaced HTML Drag and Drop API with pointer events for cross-device compatibility
  • Converted from JSX to TSX with proper TypeScript types
  • Implemented a custom drag ghost component for visual feedback

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
useDnD.tsx New comprehensive hook providing pointer-based drag and drop functionality with TypeScript
App.tsx Converted to TypeScript and updated to use new drag and drop system
Sidebar.tsx Converted to TypeScript and replaced drag events with pointer events
index.tsx Added null check for container element
index.css Added active cursor state for dragging elements
README.mdx Updated documentation to reflect pointer events implementation
DnDContext.jsx Removed old context implementation
App.jsx Removed old JSX implementation
Sidebar.jsx Removed old JSX implementation

@@ -4,6 +4,9 @@ import App from './App';
import './index.css';

const container = document.querySelector('#app');
if (!container) {
throw new Error("Root container '#app' not found");
}
const root = createRoot(container);
Copy link
Preview

Copilot AI Aug 11, 2025

Choose a reason for hiding this comment

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

The createRoot call should use the non-null assertion operator since we've already verified container is not null, or the type should be updated to reflect this.

Suggested change
const root = createRoot(container);
const root = createRoot(container!);

Copilot uses AI. Check for mistakes.

return;
}

(event.target as HTMLElement).releasePointerCapture(event.pointerId);
Copy link
Preview

Copilot AI Aug 11, 2025

Choose a reason for hiding this comment

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

The event.target might not be an HTMLElement. You should check if the target supports releasePointerCapture before calling it to avoid runtime errors.

Suggested change
(event.target as HTMLElement).releasePointerCapture(event.pointerId);
if (
event.target &&
typeof (event.target as any).releasePointerCapture === 'function'
) {
(event.target as HTMLElement).releasePointerCapture(event.pointerId);
}

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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make Drag and Drop Example work on Touch Devices
1 participant