Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

angular-draggable-droppable

mattlewis92442.8kMIT8.0.0TypeScript support: included

Drag and drop for angular 15.0+

angular2, angular, draggable, droppable, drag, drop

readme

angular 15.0+ drag and drop

Sponsorship Build Status codecov npm version Twitter Follow

Demo

https://mattlewis92.github.io/angular-draggable-droppable/

Table of contents

About

Observable powered drag and drop for angular 15.0+

Installation

Install through npm:

npm install angular-draggable-droppable

Then use it in your app like so:

import { Component, NgModule } from '@angular/core';
import { DragAndDropModule } from 'angular-draggable-droppable';

@NgModule({
  declarations: [DemoApp],
  imports: [DragAndDropModule],
  bootstrap: [DemoApp],
})
class DemoModule {}

@Component({
  selector: 'demo-app',
  template: `
    <div mwlDraggable (dragEnd)="dragEnd($event)">Drag me!</div>
    <div mwlDroppable (drop)="this.droppedData = $event.dropData">
      <span [hidden]="droppedData">Drop here</span>
      <span [hidden]="!droppedData"
        >Item dropped here with data: "{{ droppedData }}"!</span
      >
    </div>
  `,
})
class DemoApp {
  droppedData: string;

  dragEnd(event) {
    console.log('Element was dragged', event);
  }
}

Note: if draggable elements are inside a scrollable element then you will need to add mwlDraggableScrollContainer as an attribute to the scrollable container.

You may also find it useful to view the demo source.

Documentation

All documentation is auto-generated from the source and can be viewed here: https://mattlewis92.github.io/angular-draggable-droppable/docs/

Alternatives

I wrote this library because I needed drag and drop whilst snapping to a grid. If you don't need this feature then I recommend checking out one of these other awesome drag and drop libraries:

Development

Prepare your environment

Development server

Run pnpm start to start a development server on port 8000 with auto reload + tests.

Testing

Run pnpm test to run tests once or pnpm test:watch to continually run tests.

Release

pnpm release

License

MIT

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

8.0.0 (2022-12-11)

⚠ BREAKING CHANGES

  • angular 15 or higher is now required to use this package

build

7.0.0 (2022-08-02)

⚠ BREAKING CHANGES

  • angular 14 or higher is now required to use this package

build

6.1.0 (2022-04-19)

Features

  • droppable: add clientX, clientY and target to all output events (#113) (0e8e0a8)

6.0.1 (2022-04-12)

6.0.0 (2021-12-11)

⚠ BREAKING CHANGES

  • angular 12 or higher is now required to use this package

Features

  • publish package in ivy partial compilation mode (2c37cc9)

5.0.0 (2021-08-30)

⚠ BREAKING CHANGES

  • The activeLongPressDrag and longPressConfig inputs have been removed on the mwlDraggableScrollContainer directive.

To migrate use [touchStartLongPress]="{delay: 300, delta: 30}" on the mwlDraggable element instead.

  • if you were using the UMD bundle @mattlewis92/dom-autoscroller will no longer be bundled inside it and you may need to adjust your system.js config accordingly
  • angular 10 or higher is now required to use this package

Features

  • remove deprecated inputs on mwlDraggableScrollContainer directive (2766f33)

build

  • don't bundle @mattlewis92/dom-autoscroller anymore (3c41375)
  • upgrade to angular 10 (907f637)

4.6.0 (2020-12-28)

Features

  • add validateDrop to mwlDroppable directive (#111) (8850ddf)

4.5.6 (2020-10-22)

Bug Fixes

  • prevent error on drag end (4a6bdbb)

4.5.5 (2020-10-20)

Bug Fixes

  • ensure dragging output is never called unless dragging an item (1661d72)

4.5.4 (2020-09-12)

Bug Fixes

  • upgrade dom auto scroller library to prevent commonjs warnings (3f079fe)

4.5.3 (2020-07-09)

4.5.2 (2020-07-09)

4.5.1 (2020-06-19)

4.5.0 (2020-06-17)

Features

  • allow auto scroll options to be configured (46892ac)

4.4.6 (2020-05-29)

Bug Fixes

  • umd: use correct sourcemaps in umd bundle (30cfca3)

4.4.5 (2020-05-22)

Bug Fixes

  • allow any angular version above 6 (2aff5f0)

4.4.4 (2020-04-19)

Bug Fixes

  • always disable document scroll when dragging (7276cab)

4.4.3 (2020-04-19)

Bug Fixes

  • disable text selection in safari (d044523)

4.4.2 (2020-04-19)

Bug Fixes

  • only enable long press drag delay if inside a scrollable element (0a30e09)
  • remove scroll glitch on touch devices when dragging (fe9bd5e)

4.4.0 (2020-04-18)

Features

  • allow setting drag start delay on touch devices (c9b28a5)

Bug Fixes

  • disable text selection when dragging on ios safari (ca83a33)

4.3.12 (2020-04-12)

Bug Fixes

  • remove need for server side rendering hacks (7c96113)

4.3.11 (2020-04-12)

Bug Fixes

  • allow multiple dragActiveClass (60844ec)
  • support multiple drag over and drag active classes (ad50f0e)

4.3.10 (2020-03-01)

4.3.9 (2020-03-01)

Bug Fixes

  • only allow dragging when using a left click (d3eecde)

4.3.8 (2019-10-18)

4.3.7 (2019-10-11)

Bug Fixes

  • revert change to ghost element positioning (e0128e5)

4.3.6 (2019-10-11)

4.3.5 (2019-10-08)

4.3.4 (2019-10-08)

Bug Fixes

  • restore compatibility with angular 6 and 7 (f110c8e), closes #97

4.3.3 (2019-10-07)

Bug Fixes

  • allow angular 9 peer dependency (cb7cf2e)

4.3.2 (2019-06-26)

Bug Fixes

  • restore compatibility with stackblitz (ee94dc5)

4.3.1 (2019-06-05)

Bug Fixes

  • restore compatibility with angular universal (7fbaa2a)

4.3.0 (2019-04-21)

Bug Fixes

  • expose ValidateDrag type (32f4ce3)

Features

  • expose css transform on validate drag function (3c5c5b9)
  • support auto scrolling when dragging (78bdeb5)

4.2.0 (2019-03-17)

Features

  • expose ghost element and starting mouse position on ghost element created event (d233788), closes #81 #85

4.1.0 (2019-02-17)

Bug Fixes

  • allow angular 8 peer dependency (f936805)

Features

  • draggable-scroll-container: Added input activeLongPressDrag (#79) (f98f586), closes #78

4.0.2 (2018-09-18)

Bug Fixes

  • include readme and licence in npm (cfff617)

4.0.1 (2018-09-01)

Bug Fixes

  • allow draggable elements insider other draggable elements to be dragged (700fef1), closes #61

4.0.0 (2018-08-29)

Bug Fixes

  • account for the window being scrolled whilst dragging (566bf78)
  • allow dragging the element inside a scrollable container (6e0a1a3), closes #25
  • always remove global styles when clicking draggable elements (c428eed), closes #44
  • append the ghost element to the body (4f23661)
  • bump up z-index of element being dragged (9d0f754)
  • don't fire drop events when the droppable element is scrolled out of the view (4c9224b)
  • don't highlight text when dragging elements (67d3a5e), closes #28
  • maintain old ghost element behaviour by default (cf1bc61)
  • preserve original element styles after dragging (f36ed2d)
  • remove automatic pointer-events:none on dragged element (bfe9bb4)
  • remove margin on the ghost element (06396e6)
  • remove the drag helper provider from the public api (48d4fe6)
  • round snap grids so dragging from each side is even (fa8434b)
  • set dimensions and z-index on ghost element (9b5a6b0)
  • dragCursor: don't default the drag cursor to move (0a95ac7)
  • droppable: correctly account for scroll events when dragging elements (c5ef775), closes #23
  • droppable: dont throw when immediately destroying the directive (dd3e89e)

Features

  • dragActiveClass: add class when dragging element (ee1d06c)
  • dragCancel$: allow the drag to be cancelled (538f9b7), closes #30
  • draggable: add option to show the original element while dragging (d010733)
  • dragOverClass: add a class when an element is dragged over it (76852bc)
  • droppable: add css class when any element is being dragged (5995f81)
  • add a way of setting the scroll container if not the window (9831d36)
  • ghostElementAppendTo: allow the ghost element parent to be customised (f51214e)
  • ghostElementCreated: emit new event after the ghost element is created (22530b9)
  • ghostElementTemplate: allow changing the ghost element contents (ecc96ec)
  • expose interfaces for all events (c174023)
  • remove the DragAndDropModule.forRoot method (5ae52a7)

Performance Improvements

  • deregister scroll listener once drag complete (7e50d74)
  • only recalculate the bounding rectangle once after scrolling (d72e16b)
  • only recompute draggable position on window scroll (f6a5cde)

BREAKING CHANGES

  • The DragAndDropModule.forRoot method was removed. To migrate just import the DragAndDropModule module directly
  • the drag helper provider is now no longer exported as part of the public api, just remove it from your code to migrate
  • A cloned element is now created when the element is being dragged, and the dragged element is set to be positioned fixed. This may break some apps in some edge cases.
  • The dragStart $event.x and $event.y values were removed as these were always 0
  • pointer-events:none is no longer automatically applied to elements while they are being dragged. To migrate use the dragActiveClass option and set this yourself with css
  • dragCursor: The drag cursor will no longer be set to move by default, to restore the behaviour set dragCursor="move" or use CSS on the draggable elements to change the cursor

3.0.1 (2018-06-05)

Bug Fixes

  • drag: style assignment for dragged element on IE (#33) (d0372ec), closes #29

3.0.0 (2018-05-09)

Features

BREAKING CHANGES

  • angular 6 and rxjs 6 or higher are now required to use this package

2.0.0 (2017-12-26)

Bug Fixes

  • only call drag start and end outputs when the element is actually dragged (45c6b5f), closes #21 #20

Features

  • upgrade to angular 5 (4159ce2)
  • use lettable rxjs operators (9fca12a)
  • use ng-packagr for building the package (57dd436)
  • dragPointerDown: add a new output to repliate the old dragStart behaviour (4a58c61)

BREAKING CHANGES

  • The UMD module path has changed from angular-draggable-droppable/dist/umd/angular-draggable-droppable.js to angular-draggable-droppable/bundles/angular-draggable-droppable.umd.js. System.js users will need to update their config.
  • rxjs operators will now no longer be added to the observable prototype. Also rxjs

    = 5.5.x or higher is required

  • Angular 5 or higher is now required to use this package
  • drag start and end events are now only called when the element is actually dragged, use regular mousedown and mouseup events to get the old behaviour

1.1.1 (2017-10-21)

Bug Fixes

  • allow angular 5 peer dependency (1265bee)

1.1.0 (2017-09-22)

Features

  • draggable: allow the draggable cursor to be customised (897b3fe)

1.0.2 (2017-09-18)

Bug Fixes

  • draggable: fire dragEnd event when the event was not dragged (73d65d7), closes #17

1.0.1 (2017-04-14)

Bug Fixes

  • draggable: prevent text from being highlighted in firefox (7d859c1)

1.0.0 (2017-03-24)

Features

  • ng4: upgrade to angular 4 (42631bc)

BREAKING CHANGES

  • ng4: angular 4.0 or higher is now required to use this library. The upgrade should be seamless for most users

0.6.0 (2017-03-23)

Features

  • draggable: make dragging work on touch devices (dc0f863)

0.5.4 (2017-03-04)

Performance Improvements

  • draggable: lazily create all mouse event listeners (3c99d40)

0.5.3 (2017-03-04)

Bug Fixes

  • move dependencies to dev (17a2ccc)

0.5.2 (2017-03-04)

Bug Fixes

  • loosen peer dependency to allow angular 4 (bcc9080)

Performance Improvements

  • draggable: lazily create the mouse move listener (bebd925)
  • run all event listeners outside of angulars zone (d7c9256)

0.5.1 (2017-01-06)

Bug Fixes

  • draggable: allow draggable events to be clicked (44ea67e)

0.5.0 (2016-12-21)

Features

  • dragAndDropModule: add forRoot method (00f6989)

BREAKING CHANGES

  • dragAndDropModule: You must now import the DragAndDropModule with the forRoot method

0.4.0 (2016-12-18)

Features

  • draggable: remove the dragContainer option (5aca67d)

BREAKING CHANGES

  • draggable: the dragContainer option has been removed as it didn't work in all cases and can be

implemented yourself with the validateDrag option

0.3.1 (2016-12-18)

Bug Fixes

  • draggable: make the dragEnd output respect the validateDrag input (26cfa7e)

0.3.0 (2016-12-12)

Features

  • draggable: add dragContainer option (fb75711), closes #10

0.2.3 (2016-12-11)

Bug Fixes

  • draggable: allow events to be dragged back into their original positions (7831903)

0.2.2 (2016-12-11)

Bug Fixes

  • draggable: only emit the dragEnd event once (52e9a22)

0.2.1 (2016-12-10)

Bug Fixes

  • revert duplicate dragging fix as it caused worse errors (7476301)

0.2.0 (2016-12-10)

Bug Fixes

  • completely remove applied styled after dragging (3445337)
  • draggable: dont fire duplicate dragging events with the same coordinates (222914b), closes #6
  • draggable: when dragging is disabled, no drag events should be emitted (729f24e)
  • droppable: only allow dropping of events when the cursor is inside (652d632), closes #5

Features

  • draggable: auto change the cursor to the move icon on hover (50d1962), closes #9
  • snapGrid: rename to dragSnapGrid (a77d07a), closes #7
  • validateDrag: add the validate drag input (9e5ac95), closes #8

BREAKING CHANGES

  • droppable: the drag enter, leave and drop events will not fire until cursor is inside the droppable element. This is to mimic how native drag and drop works
  • snapGrid: The snapGrid input has been renamed to dragSnapGrid

0.1.1 (2016-12-09)

Bug Fixes

  • draggable: disable pointer events on the element when dragging (f29b424)

0.1.0 (2016-11-27)

Bug Fixes

  • draggable: dispose of observables when the component is destroyed (710c7f7)
  • prevent the default move move interaction on dragging (d2fdcde)

Features

  • dragAxix: allow the drag axis to be locked to just x and y (38fd4b5), closes #2
  • draggable: add mwlDraggable directive (c6771eb)
  • droppable: add the mwlDroppable directive (6016f12), closes #1
  • ghostDragEnabled: add option to disable the ghost dragging effect (709327c), closes #3
  • snapGrid: implement draggable snap grids (16a3df8), closes #4