Skip to content
← All articles

Tutorials ·

How to Make Draggable Cards and Items in React with Motion

UI Layouts

On this page

Draggable cards add direct manipulation to an otherwise static canvas.

Live example from UI Layouts

  • Follow me on X

    Get more update follow me on X

    32.8.2024Click
  • Star the repo

    If you like star the repo

    32.8.2024Click
  • Share it with your friend

    if you like it, please Share it with your friend

    32.8.2024Click

Distinguish free drag from sorting

Dragging an item visually does not automatically update a list order. Decide whether the item returns, keeps its position or commits a reordered model.

Set constraints at the container

Use a reference to a bounding region and test it after resize. Preserve a clear grab handle if the card contains buttons or inputs.

Handle touch and keyboard

Do not disable scrolling on the entire page just to make a card draggable. Provide keyboard actions for any drag operation that changes saved application state.

Implementation pattern

The following focused snippet demonstrates the principle, not the complete UI Layouts implementation. The live example and linked documentation contain the full source.

<motion.div drag dragConstraints={containerRef} dragElastic={0.12}>Drag me</motion.div>

Explore the source

Open the drag items component documentation for the full implementation, examples and any required dependencies. Test the interaction on a narrow screen and with keyboard navigation before adapting it to production.