timepicker-ui
4.6.0GitHub
timepicker-ui
Guides / Month and Year Pickers

Month and Year Pickers

calendar.precision makes @pglejzer/datepicker-ui, the companion of timepicker-ui, select a whole month or year instead of a day.

Month precision

#

calendar.precision is "day" (the default), "month" or "year". The picker then selects a whole month or year. It works in single mode only. Another mode emits invalid-option and uses "day".

Month
import DatepickerUI from "@pglejzer/datepicker-ui";
import "@pglejzer/datepicker-ui/index.css";
new DatepickerUI("#month", {
calendar: { precision: "month" },
}).create();

A docked month picker opens on the month grid and a modal one adds a year button above it. A month can be picked when any of its days is available.

Year precision

#
Year
import DatepickerUI from "@pglejzer/datepicker-ui";
import "@pglejzer/datepicker-ui/index.css";
new DatepickerUI("#year", {
calendar: { precision: "year" },
}).create();

A year picker opens on the year grid. A year can be picked when it is inside minDate, maxDate and ui.yearRange.

Value format

#

The value is the first day of the period, and DateValue.value is YYYY-MM for months and YYYY for years. The input text drops the finer parts of the format, so MM/dd/yyyy shows 10/2026, and typing 10/2026 works. setValue() accepts a Date, "2026-10" or "2026-10-17".

With precision: "month" the ui.format pattern may leave out the day ("MM/yyyy", "yyyy-MM"), and with "year" it may be the year alone ("yyyy"). A full pattern works too: the parts finer than the precision are dropped, so "dd.MM.yyyy" shows 10.2026 for a month.

At these precisions select:day carries the picked period in value.value. There is no input view, and ui.mask and ui.startView do not apply.

Start view

#

ui.startView ("day", "month" or "year") decides which panel opens first. A docked picker opens the month or year menu, and a modal picker opens the month grid or year grid. It suits a birthday field.

Start view
import DatepickerUI from "@pglejzer/datepicker-ui";
import "@pglejzer/datepicker-ui/index.css";
new DatepickerUI("#birthday", {
ui: { startView: "year" },
}).create();

When startView is ignored

ui.initialView: "input" wins over startView. It is also ignored in range mode and when calendar.precision is not "day".
#
Esc