onSlotClick
Hears a bookable slot (availableSlots) clicked — or Enter on it.
| Type | (slot: AvailableSlot) => void |
|---|---|
| Default | not set |
Live update (update()) | Yes |
| Declared in | packages/dom/src/settings.ts |
What it does
Section titled “What it does”It receives the slot exactly as you gave it — its start, end and any
field of yours (resourceId, seats from @dzcalendar/pro/slots, an id). The calendar creates
nothing: book it, and have your server check it again (checkSlot from
@dzcalendar/slots) before saving, since someone else may have taken it.
Without onSlotClick, slots are only shown, not clickable.
Example
Section titled “Example”import { createCalendar } from '@dzcalendar/dom';
const calendar = createCalendar(element, { timeZone: 'Europe/Paris', availableSlots: [], onSlotClick: async (slot) => { const res = await fetch('/api/bookings', { method: 'POST', body: JSON.stringify({ start: slot.start.toString() }) }); if (!res.ok) alert('Just taken, sorry.'); calendar.refetch(); },});import { Component } from '@angular/core';import type { AvailableSlot } from '@dzcalendar/core';import { DZ_CALENDAR } from '@dzcalendar/angular';
@Component({ selector: 'app-agenda', imports: [DZ_CALENDAR], template: `<dz-calendar timeZone="Europe/Paris" [availableSlots]="[]" (slotClick)="book($event)" />`,})export class Agenda { book(slot: AvailableSlot): void { console.log('book', slot.start.toString()); }}import { DzCalendar } from '@dzcalendar/react';
export function Agenda() { return <DzCalendar timeZone="Europe/Paris" availableSlots={[]} onSlotClick={(slot) => console.log('book', slot.start.toString())} />;}<script setup lang="ts">import type { AvailableSlot } from '@dzcalendar/core';import { DzCalendar } from '@dzcalendar/vue';
const book = (slot: AvailableSlot) => console.log('book', slot.start.toString());</script>
<template> <DzCalendar time-zone="Europe/Paris" :available-slots="[]" @slot-click="book" /></template>In the frameworks it is an output: Angular’s (slotClick), React’s onSlotClick, Vue’s @slot-click.
See also
Section titled “See also”availableSlots— the slots drawn.onDateClick— a click on other time.businessHours— a provider’s hours.