timepicker-ui
4.6.0GitHub
timepicker-ui
Guides / Display Modes

Date Picker Display Modes

@pglejzer/datepicker-ui, the companion of timepicker-ui, opens as a docked popover, a modal dialog or an inline calendar. ui.displayMode picks the surface.

Display modes

#

ui.displayMode picks the surface. The default is "auto".

ValueSurface
"auto"Modal dialog when the viewport is below 600 px wide or 480 px tall, docked otherwise.
"docked"Popover next to the input.
"modal"Dialog with a backdrop.

Docked

#

A docked picker is a popover placed next to the input. It uses CSS anchor positioning where the browser supports it, and a JavaScript fallback otherwise.

Docked
import DatepickerUI from "@pglejzer/datepicker-ui";
import "@pglejzer/datepicker-ui/index.css";
new DatepickerUI("#date", {
ui: { displayMode: "docked" },
}).create();
#

A modal picker is a native <dialog> with a backdrop. It is the surface "auto" picks on small screens.

Modal
import DatepickerUI from "@pglejzer/datepicker-ui";
import "@pglejzer/datepicker-ui/index.css";
new DatepickerUI("#date", {
ui: { displayMode: "modal" },
}).create();

Inline

#

For an inline picker, set ui.inline.enabled and give ui.inline.container a selector or an element. create() mounts it. It has no open triggers.

index.html
<input id="date" />
<div id="calendar"></div>

An inline picker hides the footer unless ui.footer is true. Without a footer there is no confirm button, so set behavior.commitOnChange to write each pick to the input. The same applies to behavior.closeOnSelect.

Inline
import DatepickerUI from "@pglejzer/datepicker-ui";
import "@pglejzer/datepicker-ui/index.css";
new DatepickerUI("#date", {
ui: { inline: { enabled: true, container: "#calendar" } },
behavior: { commitOnChange: true },
}).create();

Inline footer

Set ui.footer: true instead of commitOnChange to keep the confirm and cancel buttons under an inline calendar.

Full screen range picker

#

A range picker in a modal opens full screen below ui.fullscreen. true means below 600 px, a number means below that width in pixels and false means never. The width is read when the picker opens.

index.ts
new DatepickerUI("#range", {
calendar: { mode: "range" },
ui: { displayMode: "modal", fullscreen: 768 },
}).create();

Where the modal is appended

#

ui.appendTo takes a selector or an element for the modal dialog. By default the dialog is appended to the host.

index.ts
new DatepickerUI("#date", {
ui: { displayMode: "modal", appendTo: "#modal-root" },
}).create();

Toggle button

#

ui.toggleButton adds an extra element that opens the picker, such as a calendar icon button. When it is not a <button>, Enter and Space open the picker. The picker sets aria-expanded on it and gives it an accessible name from labels.openCalendar.

index.html
<input id="date" />
<button id="open" type="button">Choose date</button>
Toggle buttonCalendar icon button next to the field
import DatepickerUI from "@pglejzer/datepicker-ui";
import "@pglejzer/datepicker-ui/index.css";
new DatepickerUI("#date", {
ui: { toggleButton: "#open" },
}).create();

Page scroll in a modal

#

A modal picker locks page scroll while it is open. Set ui.allowPageScroll to true to keep the page scrollable.

#
Esc