Skip to content

Calendar Picker

A Calendar picker component that combines an input field with a calendar popup for easy date selection. The component supports various date formats, time selection, dialog mode for mobile devices, and extensive customization options.

  • Calendar component (automatically included)
  • DateTime utilities
  • Farbe color utilities

See the Example by Serhii Pimenov on CodePen.

<!-- Simple date picker -->
<input data-role="calendar-picker">
<!-- With initial value -->
<input data-role="calendar-picker" value="2024/01/15">
<!-- With label -->
<input data-role="calendar-picker" data-label="Select date:">
<!-- Custom date format -->
<input data-role="calendar-picker"
data-format="DD, MMM YYYY"
data-input-format="DD/MM/YYYY">
<!-- With time selection -->
<input data-role="calendar-picker"
data-show-time="true"
data-initial-time="14:30">
<!-- Dialog mode for mobile -->
<input data-role="calendar-picker"
data-dialog-mode="true"
data-dialog-point="640">
<!-- With date restrictions -->
<input data-role="calendar-picker"
data-min-date="2024/01/01"
data-max-date="2024/12/31">
<!-- With clear button -->
<input data-role="calendar-picker"
data-clear-button="true">
// Initialize programmatically
const picker = Metro.makePlugin('#myInput', 'calendar-picker', {
format: 'DD/MM/YYYY',
showTime: true,
clearButton: true
});
// Get component instance
const picker = Metro.getPlugin('#myInput', 'calendar-picker');
ParameterTypeDefaultDescription
labelstring""Label text displayed above the input
valuestring""Initial date value
calendarPickerDeferrednumber0Deferred initialization delay
nullValuebooleantrueAllow null/empty values
useNowbooleanfalseUse current date as default
prependstring""HTML content to prepend to input
dialogModebooleanfalseForce dialog mode
dialogPointnumber640Screen width breakpoint for dialog mode
dialogOverlaybooleantrueShow overlay in dialog mode
overlayColorstring”#000000”Overlay background color
overlayAlphanumber0.5Overlay transparency
sizestring”100%“Input width
formatstringMETRO_DATE_FORMATDisplay date format
inputFormatstringnullInput parsing format
clearButtonbooleanfalseShow clear button
calendarButtonIconstring”📅“Calendar button icon
clearButtonIconstring”❌“Clear button icon
prevMonthIconstring”⯇“Previous month icon
nextMonthIconstring”⯈“Next month icon
prevYearIconstring”⯇“Previous year icon
nextYearIconstring”⯈“Next year icon
copyInlineStylesbooleanfalseCopy inline styles to container
openModestring”auto”Calendar open direction (“auto”, “up”, “down”)
widebooleanfalseUse wide calendar layout
widePointnumber640Screen width for wide layout
showTimebooleanfalseEnable time selection
outsidebooleantrueShow dates outside current month
weekStartnumber0First day of week (0=Sunday, 1=Monday)
eventsarray[]Calendar events
initialTimestringnullInitial time value (HH:MM)
initialHoursnumbernullInitial hours
initialMinutesnumbernullInitial minutes
headerFormatstring”dddd, MMM DD”Calendar header format
showWeekNumberbooleanfalseShow week numbers
ripplebooleanfalseEnable ripple effect
rippleColorstring”#000000”Ripple effect color
specialarray[]Special dates array
excludearray[]Excluded dates array
minDatestringnullMinimum selectable date
maxDatestringnullMaximum selectable date
yearsBeforenumber100Years before current year
yearsAfternumber100Years after current year
ParameterDescription
clsCalendarCalendar container classes
clsCalendarHeaderCalendar header classes
clsCalendarContentCalendar content classes
clsCalendarMonthsMonth view classes
clsCalendarYearsYear view classes
clsCalendarTimeTime picker classes
clsTimeTime container classes
clsTimeHoursHours input classes
clsTimeMinutesMinutes input classes
clsTimeButtonTime button classes
clsTimeButtonPlusPlus button classes
clsTimeButtonMinusMinus button classes
clsTodayToday date classes
clsSelectedSelected date classes
clsExcludedExcluded date classes
clsOverlayOverlay classes
clsPickerPicker container classes
clsInputInput field classes
clsPrependPrepend content classes
clsLabelLabel classes
  • clear() - Clear the selected date and reset to empty value.
  • val(value, format) - Get or set the picker value. Returns object with date and time if no arguments provided.
  • disable() - Disable the calendar picker.
  • enable() - Enable the calendar picker.
  • toggleState() - Toggle between enabled and disabled states.
  • getTime(asString) - Get the selected time. Returns array [hours, minutes] or string “HH:MM” if asString is true.
  • changeAttribute(attributeName, newValue) - Change component attribute dynamically.
  • destroy() - Destroy the component and clean up event listeners.
const picker = Metro.getPlugin('#myPicker', 'calendar-picker');
// Set a new date
picker.val('2024/12/25');
// Get current value
const currentValue = picker.val(); // Returns {date: Date, time: [hours, minutes]}
// Clear the picker
picker.clear();
// Get time as string
const timeString = picker.getTime(true); // Returns "14:30"
// Disable the picker
picker.disable();
EventDescription
onDayClickFired when a day is clicked in the calendar
onCalendarPickerCreateFired when the calendar picker is created
onCalendarShowFired when the calendar popup is shown
onCalendarHideFired when the calendar popup is hidden
onChangeFired when the selected date changes
onPickerChangeFired when the picker value changes
onMonthChangeFired when the calendar month changes
onYearChangeFired when the calendar year changes
<input data-role="calendar-picker"
data-on-change="handleDateChange"
data-on-calendar-show="handleCalendarShow">
<script>
function handleDateChange(date) {
console.log('Date changed to:', date);
}
function handleCalendarShow(calendar) {
console.log('Calendar shown');
}
</script>
  • .calendar-picker - Main container class
  • .calendar-for-picker - Calendar popup container
  • .input-calendar-button - Calendar button
  • .input-clear-button - Clear button
  • .open - Calendar is open
  • .open-up - Calendar opens upward
  • .dialog-mode - Dialog mode active
  • .disabled - Component is disabled
  • .focused - Input is focused
  • .calendar-wide - Wide calendar layout
  • .compact - Compact calendar layout
  • The component automatically switches to dialog mode on mobile devices based on the dialogPoint setting
  • Date formats follow the Metro UI date formatting conventions
  • The component integrates with the Metro UI theming system
  • Time selection is optional and can be enabled with the showTime parameter
  • The calendar popup automatically positions itself to stay within the viewport
  • Use appropriate date formats for your locale and user expectations
  • Enable dialog mode for better mobile experience
  • Set reasonable min/max date ranges to guide user selection
  • Use clear button for optional date fields
  • Consider time selection only when necessary to avoid interface complexity
  • Test the component across different screen sizes to ensure proper responsive behavior