mirror of
https://github.com/Shopify/draggable.git
synced 2025-12-08 20:15:56 +00:00
Droppable
Droppable is built on top of Draggable and allows you to declare draggable and droppable elements via options.
Droppable fires two events on top of the draggable events: droppable:over and droppable:out.
Import
import {Droppable} from '@shopify/draggable';
import Droppable from '@shopify/draggable/lib/droppable';
<script src="https://cdn.jsdelivr.net/npm/@shopify/draggable@1.0.0-beta.5/lib/draggable.bundle.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@shopify/draggable@1.0.0-beta.5/lib/droppable.js"></script>
API
Check out Draggables API for the base API
Options
Check out Draggables options for the base options
droppable {String|HTMLElement[]|NodeList|Function}
A css selector string, an array of elements, a NodeList or a function returning elements for droppable
elements within the containers specified.
Events
Check out Draggables events for base events
| Name | Description | Cancelable | Cancelable action |
|---|---|---|---|
droppable:over |
Gets fired when dragging over droppable element | true | Prevents drop |
droppable:out |
Gets fired when dragging out of a droppable element | true | Prevents release |
Classes
Check out Draggables class identifiers
| Name | Description | Default |
|---|---|---|
droppable:active |
Class added on droppables when drag starts | draggable-droppable--active |
droppable:occupied |
Class added on droppable element, when it contains a draggable | draggable-droppable--occupied |
Example
This sample code will make list items draggable and allows to drop them inside another element:
import {Droppable} from '@shopify/draggable';
const droppable = new Droppable(document.querySelectorAll('ul'), {
draggable: 'li',
droppable: '#dropzone',
});
droppable.on('droppable:over', () => console.log('droppable:over'));
droppable.on('droppable:out', () => console.log('droppable:out'));