React-Draggable

A simple, dependency-free React component for making any element draggable.

Library
npm
v4.7.2
9,287 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
78 /100 Good
Development Activity 76
Maintenance 64
Community 72
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
78 /100 Good
Architecture 82
Code Quality 78
Innovation 68
Learning Curve 85

React-Draggable wraps an existing element and adds drag event handlers and CSS-transform-based positioning, without inserting any wrapper DOM node. Because it moves elements with CSS transforms rather than absolute-position offsets, dragging works regardless of the element’s original positioning scheme (relative, absolute, or static), and elements can be repositioned between drags without visual glitches.

The package ships two components: <Draggable>, a batteries-included component that manages its own position state, class names, and styling; and <DraggableCore>, a headless variant that exposes the same drag callbacks without applying any transforms or managing state, intended for libraries like react-resizable and react-grid-layout that need full control over positioning.

What You Get

  • A <Draggable> component that wraps a child element and makes it draggable via CSS transforms, with no extra DOM nodes inserted
  • A headless <DraggableCore> component exposing drag start/move/stop callbacks without managing position state or styles
  • Configurable drag axis, bounds, grid-snapping, and a custom drag handle or cancel selector
  • Controlled and uncontrolled positioning modes, with onDrag/onStart/onStop callbacks carrying delta and absolute coordinates
  • Content Security Policy support via a nonce prop or opt-out of the injected user-select style
  • Bundled TypeScript type definitions

Common Use Cases

  • Draggable modals, panels, or floating widgets in dashboard and admin UIs
  • Building custom drag-and-drop or free-form layout tools on top of <DraggableCore>
  • Powering higher-level grid layout libraries such as react-grid-layout and react-resizable
  • Draggable annotation handles or markers in canvas/SVG-based editors
  • Kanban-style or whiteboard-style interfaces where elements need free positioning within bounds

Under The Hood

Architecture - <Draggable> (lib/Draggable.tsx) is a stateful wrapper around <DraggableCore> (lib/DraggableCore.tsx), the low-level component that attaches pointer/mouse/touch event listeners directly to the child DOM node (obtained via the required nodeRef) and computes position deltas on every move event. <Draggable> layers position state, CSS class name toggling (react-draggable, -dragging, -dragged), and CSS-transform application on top of the callbacks <DraggableCore> provides, while <DraggableCore> itself renders no additional markup and applies no transforms, leaving positioning entirely to the caller — this split is what lets react-grid-layout and react-resizable reuse the drag mechanics with their own layout logic.

Tech Stack - The library is authored in TypeScript (lib/*.tsx) and built with tsup into CJS, ESM, and a minified UMD/web bundle (build/web/react-draggable.min.js) referenced by the unpkg field for CDN usage. It has no runtime dependencies beyond React itself (peer dependency), keeping the installed footprint minimal. Tests run under Vitest, including a browser-mode configuration (vitest.browser.config.js) for real DOM/pointer-event behavior alongside the standard jsdom suite.

Code Quality - The test/ directory covers both components’ props and callback behavior, with yarn test:all running the standard suite plus a real-browser pass, indicating explicit attention to drag interactions that are hard to fully verify in jsdom alone. ESLint (flat config) and TypeScript’s tsc --noEmit typecheck are wired into make lint, and the maintainers track a versioned React-compatibility table (2.x through 4.x) in the README, showing deliberate handling of breaking changes across React major versions.

API Design - The API favors minimal ceremony: wrapping a single <div> in <Draggable> is enough to make it draggable, and the required nodeRef prop (replacing the deprecated findDOMNode pattern) is the main piece of boilerplate needed for React Strict Mode compatibility. Prop naming is consistent between the two components (axis, bounds, handle, cancel, onDrag/onStart/onStop), and the README documents a Content Security Policy escape hatch (nonce prop or enableUserSelectHack={false}) that many comparable libraries omit entirely.

Used by 14 apps in this directory

TypeScript
99%
Other

Papermark

Digital Signiture · File Storage

9,263

Open-source DocSend alternative with page-by-page analytics, secure data rooms, and custom domains for document sharing.

View details
78
Repo Health
63
Technical
66
Dependency
Built with
TypeScript 99%
Updated 2 months ago
TypeScript
90%
MIT

Plasmic

CMS · Design Tools · Low Code Platforms

7,125

The open-source visual builder that lets teams design React apps and websites with drag-and-drop while integrating seamlessly with your codebase.

View details
81
Repo Health
78
Technical
64
Dependency
Built with
TypeScript 90%
Updated 6 days ago
Python
55%
Other

PostHog

Ab Testing Experimentation · Analytics · Developer Tools

40,397

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
65
Dependency
Built with
Python 55%
TypeScript 36%
Updated 5 days ago
Python
79%
AGPL 3.0

Skyvern

AI Agents · Automation

23,257

Skyvern (YC S2023) automates browser-based workflows by pairing LLMs with computer vision, letting agents click, fill, and extract data on sites they've never seen, without brittle XPath selectors that break on every layout change.

View details
89
Repo Health
82
Technical
70
Dependency
Built with
Python 79%
TypeScript 19%
Updated 5 days ago
TypeScript
55%
Other

Tolgee

Developer Tools

4,139

In-context localization platform that lets developers and translators edit app strings directly in the running application, with AI-powered machine translation and framework SDKs for React, Angular, Vue, and Svelte.

View details
91
Repo Health
84
Technical
66
Dependency
Built with
TypeScript 55%
Kotlin 44%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers