Skip to content

onUnselect

Hears the selection shown go away by itself — a click elsewhere, Escape, another period.

Type() => void
Defaultnot set
Live update (update())Yes
Declared inpackages/dom/src/settings.ts

A person’s click outside the selection, Escape, a move to another period — or anything else that clears it: a new drag (then onSelect), the cursor moved without Shift, a change of view — clears the selection shown; this says so, with no argument — close a form that was open for it. It is not called when your code clears it (calendar.select(null)) or replaces it. A press outside the calendar counts, except on an element of your page marked data-dz-keep-selection (or inside one): a form beside the calendar keeps the selection it is about.

In the frameworks the two-way selection says the same, becoming null: use it there instead.

import { createCalendar } from '@dzcalendar/dom';
const form = document.getElementById('booking-form')!;
createCalendar(element, {
timeZone: 'Europe/Paris',
selectable: true,
onSelect: () => (form.hidden = false),
onUnselect: () => (form.hidden = true),
});

In plain JavaScript it is an option. In the frameworks, follow the two-way selection: Angular’s [(selection)], React’s onSelectionChange(null), Vue’s v-model:selection (or update:selection) becoming null.