selectable
Lets a person select a stretch of empty time — to book it, to block it.
| Type | boolean |
|---|---|
| Default | false |
Live update (update()) | Yes |
| Declared in | packages/dom/src/settings.ts |
What it does
Section titled “What it does”With selectable: true, dragging across empty time selects it: hours in
a time grid, days in a month. On the keyboard, Enter on a slot selects it
and Shift+arrows grow it (said as it grows); Enter gives it to the
application.
onSelect(selection) hears it: { start, end, allDay, resourceId? }, the
start and end in the calendar’s zone (ZonedDateTimes), or dates for whole
days — the end then the day after the last one. On a touch screen, a tap on
empty time selects one slot, with handles to stretch it. Enter (or Space) on
a slot is also a date click. The selection stays drawn until a click elsewhere, Escape or
another period (onUnselect); calendar.select(selection | null) shows or
clears one from your code. A mouse click does not select: a click is a date
click (onDateClick).
Example
Section titled “Example”import { createCalendar } from '@dzcalendar/dom';
createCalendar(element, { timeZone: 'Europe/Paris', selectable: true, onSelect: ({ start, end }) => console.log(`book ${start.toString()} → ${end.toString()}`),});import { Component, signal } from '@angular/core';import type { Selection } from '@dzcalendar/core';import { DZ_CALENDAR } from '@dzcalendar/angular';
@Component({ selector: 'app-agenda', imports: [DZ_CALENDAR], template: ` <dz-calendar timeZone="Europe/Paris" [selectable]="true" [(selection)]="selection" /> @if (selection(); as s) { <p>From {{ s.start.toString() }} to {{ s.end.toString() }}</p> }`,})export class Agenda { readonly selection = signal<Selection | null>(null);}import { useState } from 'react';import type { Selection } from '@dzcalendar/core';import { DzCalendar } from '@dzcalendar/react';
export function Agenda() { const [selection, setSelection] = useState<Selection | null>(null); return <DzCalendar timeZone="Europe/Paris" selectable selection={selection} onSelectionChange={setSelection} />;}<script setup lang="ts">import { shallowRef } from 'vue';import type { Selection } from '@dzcalendar/core';import { DzCalendar } from '@dzcalendar/vue';
const selection = shallowRef<Selection | null>(null);</script>
<template> <DzCalendar time-zone="Europe/Paris" selectable v-model:selection="selection" /></template>In the frameworks it is an input: Angular’s selectable (and the two-way [(selection)]), React’s selectable (with selection and onSelectionChange), Vue’s selectable (with v-model:selection).
Live demo
Section titled “Live demo”Drag across empty hours to select them.
See also
Section titled “See also”onSelect— what was selected.onUnselect— the selection gone.- Selection.