timepicker-ui
4.6.0GitHub
timepicker-ui
Selection / Two Range Fields

Range With Two Fields

Split a date range into a check-in and a check-out input with @pglejzer/datepicker-ui.

Start and end inputs

#

Attach the picker to the first input and point ui.endInput at the second, a selector or an element. The main input holds the start and the second holds the end. It is read when create() runs and only applies in "range" mode.

index.html
<label for="trip-start">Check-in</label>
<input id="trip-start" />
<label for="trip-end">Check-out</label>
<input id="trip-end" />
Two fields
import DatepickerUI from "@pglejzer/datepicker-ui";
import "@pglejzer/datepicker-ui/index.css";
new DatepickerUI("#trip-start", {
calendar: { mode: "range" },
ui: { endInput: "#trip-end" },
}).create();

Clicking a field opens the picker on that end. Typing commits only a complete pair, or two empty fields.

Style the active field

#

The library adds dp-ui__input--active to the input the next pick fills, and leaves its styling to the page. Add a rule such as this one:

index.css
.dp-ui__input--active {
border-color: #6d28d9;
box-shadow: inset 0 0 0 1px #6d28d9;
}

Docs: Selection Modes · Layouts · CSS Classes

Esc