Initialize the picker with optional range limits and listen for selection updates.
const pickerElement = document.getElementById('datetime-picker-1');
const picker = new DateTimePicker(pickerElement, {
minDate: '2026-02-01T09:00:00',
maxDate: '2026-12-31T18:00:00',
use12Hour: true
});
pickerElement.addEventListener('datetime-change', (event) => {
const selectedDate = event.detail; // Date or null
console.log(selectedDate);
});You can also pass range limits through data-min-date and data-max-date on the picker root element. Use ISO 8601 strings like 2026-02-01T09:00:00 for consistent parsing.
datetime-change dispatches from the picker root. event.detail is a Date when a value is applied, or null when cleared.
Call picker.destroy() before removing the element to detach event listeners and clear cached year markup.
Enter, Space, or ArrowDown on trigger opens the picker.Arrow keys move across calendar days and year options.Enter applies focused calendar day or focused year.Escape closes the picker and returns focus to the trigger.Clear resets the value and keeps the picker open for immediate reselection.Tab and Shift+Tab stay trapped inside the open dialog.