Angular CDK Drag & Drop: Multi Direction Movement

In this quick guide, we will learn how to handle movement in both directions (vertical & horizontal) using Angular CDK Drag & Drop

25th August, 2024 — 2 min read

## Angular CDK Drag & Drop The `@angular/cdk/drag-drop` module allows you to effortlessly and declaratively build drag-and-drop interfaces. It supports free dragging, list sorting, item transfers between lists, animations, touch devices, custom drag handles, previews, placeholders, horizontal lists, and axis locking. ## Reordering lists Wrapping a set of `cdkDrag` elements with `cdkDropList` groups them into a reorderable collection. As elements move, they will automatically rearrange. However, this won't update your data model; you can listen to the `cdkDropListDropped` event to update the data model after the user finishes dragging.
### Orientations Angular CDK supports 2 orientations for reordering lists: vertical (default) and horizontal. The `cdkDropList` directive assumes that lists are vertical by default. This can be changed by setting the `cdkDropListOrientation` property to `horizontal`.
### Mixed Orientation By default, `cdkDropList` sorts items by moving them with a CSS transform. This enables animated sorting for a better user experience, but it only works in one direction: either vertically or horizontally. From Angular Material `v18.1.0`, for sortable lists that need to wrap, you can set `cdkDropListOrientation="mixed"`. This uses a different sorting strategy by moving elements in the DOM, allowing items to wrap to the next line. However, it cannot animate the sorting action.
Dharmen Shah
Written by Dharmen Shah

I have around 8+ years of experience in IT industry. I have got opportunity to work at different companies with different technologies, mostly focused on Front-end, like Angular, React, Next, vanilla web stack (HTML, CSS, JavaScript).

You can find me on Twitter, Linkedin and Github.

Discuss online

Share this article

Read more

View all articles

Learn more

View courses page

Envelop
Don't miss any update

Stay up to date

Subscribe to the newsletter to stay up to date with articles, courses and much more!

Angular Material Dev

Angular Material Dev is one place stop for developers to learn about integrating Material Design in Angular applications like a pro.

Find us on X (Twitter) and LinkedIn