Skip to content

Date Picker

The DatePicker component is a wheel-based date picker that allows users to select a date by scrolling through months, days, and years.

The DatePicker component depends on:

  • WheelPicker component
  • Metro UI CSS framework
<input data-role="date-picker">
<input data-role="date-picker" data-label="Select date">
<input data-role="date-picker" data-locale="uk-UA">
<input data-role="date-picker" data-day="false">
<input data-role="date-picker" disabled data-label="Select date" id="my-datepicker">

You can enable or disable the datepicker programmatically:

// Enable
$('#my-datepicker').prop('disabled', false);
// Disable
$('#my-datepicker').prop('disabled', true);
ParameterTypeDefaultDescription
labelstring""Label for the datepicker
datepickerDeferrednumber0Deferred initialization time in milliseconds
gmtnumber0GMT timezone adjustment
formatstring”YYYY-MM-DD”Output date format
inputFormatstringnullInput date format (if different from output format)
valuestringnullInitial value for the datepicker
distancenumber3Number of visible items before and after the selected item
monthbooleantrueShow month selector
daybooleantrueShow day selector
yearbooleantrueShow year selector
minYearnumbernullMinimum selectable year (defaults to current year - 100)
maxYearnumbernullMaximum selectable year (defaults to current year + 100)
defaultYearDistancenumber100Default distance for min/max year calculation
scrollSpeednumber4Scrolling speed for the wheel picker
copyInlineStylesbooleanfalseCopy inline styles from the input element to the picker
openModestring”auto”Mode for opening the picker: “auto”, “dialog”, or “up”
clsPickerstring""Additional CSS class for the picker
clsPartstring""Additional CSS class for the date parts
clsMonthstring""Additional CSS class for the month element
clsDaystring""Additional CSS class for the day element
clsYearstring""Additional CSS class for the year element
clsLabelstring""Additional CSS class for the label
clsButtonstring""Additional CSS class for buttons
clsOkButtonstring""Additional CSS class for the OK button
clsCancelButtonstring""Additional CSS class for the Cancel button
okButtonIconstring”✓“Icon for the OK button
cancelButtonIconstring”𐄂“Icon for the Cancel button

Opens the datepicker dropdown.

Metro.getPlugin('#my-datepicker', 'date-picker').open();

Closes the datepicker dropdown.

Metro.getPlugin('#my-datepicker', 'date-picker').close();

Gets or sets the current value of the datepicker.

// Get value
const value = Metro.getPlugin('#my-datepicker', 'date-picker').val();
// Set value
Metro.getPlugin('#my-datepicker', 'date-picker').val('2023-01-15');

Gets or sets the date value with optional format.

// Get date
const date = Metro.getPlugin('#my-datepicker', 'date-picker').date();
// Set date with specific format
Metro.getPlugin('#my-datepicker', 'date-picker').date('15/01/2023', 'DD/MM/YYYY');

Disables the datepicker.

Metro.getPlugin('#my-datepicker', 'date-picker').disable();

Enables the datepicker.

Metro.getPlugin('#my-datepicker', 'date-picker').enable();

Toggles the enabled/disabled state of the datepicker.

Metro.getPlugin('#my-datepicker', 'date-picker').toggleState();
EventDescription
onSetTriggered when a date is set
onOpenTriggered when the picker is opened
onCloseTriggered when the picker is closed
onScrollTriggered when scrolling through the date options
onDatePickerCreateTriggered when the datepicker is created
<input data-role="date-picker"
data-on-set="console.log('Date set:', arguments[0])"
data-on-open="console.log('Picker opened')"
data-on-close="console.log('Picker closed')">

The DatePicker component uses the following CSS variables for styling:

VariableDefault (Light)Description
—border-colorDepends on themeBorder color for the datepicker elements
—wheel-picker-border-radiusDepends on themeBorder radius for the date wrapper
—datepicker-border-radiusDepends on themeBorder radius for the action block
:root {
--border-color: #ccc;
--wheel-picker-border-radius: 4px;
--datepicker-border-radius: 4px;
}
/* Dark theme customization */
.dark-side {
--border-color: #555;
}
  • .date-picker - Main container class
  • .date-wrapper - Container for the date parts
  • .month, .day, .year - Classes for the individual date parts
  • .sel-month - Class for the selected month
  • .action-block - Container for action buttons
  • .button - Style for buttons
  • .icon - Style for icons within buttons

Additional styling can be applied using the provided class options (clsPicker, clsPart, etc.) or by targeting the component’s CSS classes:

.date-picker .date-wrapper {
/* Custom styles for the date wrapper */
}
.date-picker .month {
/* Custom styles for the month display */
}
.date-picker .day {
/* Custom styles for the day display */
}
.date-picker .year {
/* Custom styles for the year display */
}
.date-picker .action-block {
/* Custom styles for the action buttons area */
}