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".
| Value | Surface |
|---|---|
"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.
Modal
#A modal picker is a native <dialog> with a backdrop. It is the surface "auto" picks on small screens.
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.
<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 footer
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.
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.
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.
<input id="date" /><button id="open" type="button">Choose date</button>
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.