Skip to content

droppable

What may be dropped here: an element of the page made draggable, or an event from another calendar.

Typeboolean | ((data: unknown) => boolean)
Defaultfalse
Live update (update())Yes
Declared inpackages/dom/src/settings.ts
  • true: anything. false (the default): nothing.
  • A function (data) => boolean: a filter, given the element’s data — or, for an event coming from another calendar, the event itself.

An element of the page becomes draggable with makeDraggable(el, { event, data, create? }) (@dzcalendar/dom/drag): event is what it becomes (an event without its start — the drop position gives it — or a function giving one, read when the drag starts); with create: false no event is made and onDrop alone hears the drop. Dropped, the event is made by a command checked as a gesture is (rules apply), onDrop hears the drop and onEventReceive the event — revert() takes it back. An event dragged from another calendar needs this calendar editable too (or the event editable by its own say); the calendar it left hears onEventLeave. The keyboard can do all of it: Enter on the element picks it up, Tab reaches a calendar, the arrows place it, Enter drops.

import { createCalendar } from '@dzcalendar/dom';
import { makeDraggable } from '@dzcalendar/dom/drag';
// A card of the waiting list: it becomes a 30-minute consultation where it is dropped.
makeDraggable(document.getElementById('patient-42')!, {
event: { title: 'Consultation', duration: { minutes: 30 } },
data: { patientId: 42 },
});
createCalendar(element, {
timeZone: 'Europe/Paris',
// Only patients, not the other cards of the page.
droppable: (data) => typeof data === 'object' && data !== null && 'patientId' in data,
onEventReceive: (change) => console.log('booked', change.after?.start.toString()),
});

In Angular and Vue it goes in options; in React it is a prop. The drop and the event are Angular’s (dropped) and (eventReceive), Vue’s @dropped and @event-receive, React’s onDrop and onEventReceive.