Skip to content

Time Picker

Time Picker component allows users to select time values (hours, minutes, seconds) using wheel-based interface with customizable steps and formats.

  • Metro UI Core
  • Dom library
<!-- Basic usage -->
<input data-role="time-picker">
<!-- With custom options -->
<input data-role="time-picker" data-hours-step="2" data-minutes-step="5" data-seconds="false">
<!-- With label -->
<input data-role="time-picker" data-label="Select time">
<!-- Hours and minutes only -->
<input data-role="time-picker" data-seconds="false">
<!-- With custom steps -->
<input data-role="time-picker" data-hours-step="2" data-minutes-step="15" data-seconds-step="30">
<!-- With initial value -->
<input data-role="time-picker" data-value="14:30:00">
<!-- Dialog mode (useful for mobile) -->
<input data-role="time-picker" data-open-mode="dialog">
ParameterTypeDefaultDescription
labelString""Label text for the time picker
timepickerDeferredNumber0Defer initialization of component in milliseconds
hoursStepNumber1Step value for hours (1-23)
minutesStepNumber1Step value for minutes (1-59)
secondsStepNumber1Step value for seconds (1-59)
valueString/ObjectnullInitial value for time picker
distanceNumber3Number of visible elements before and after selection
hoursBooleantrueDisplay hours
minutesBooleantrueDisplay minutes
secondsBooleantrueDisplay seconds
showLabelsBooleantrueShow labels for hours, minutes and seconds
scrollSpeedNumber4Scroll speed for wheel selection
copyInlineStylesBooleanfalseCopy inline styles from original input to component
openModeString"auto"Mode for opening dropdown: “auto”, “dialog” or “up”
clsPickerString""Additional class for time picker element
clsPartString""Additional class for each time part
clsHoursString""Additional class for hours element
clsMinutesString""Additional class for minutes element
clsSecondsString""Additional class for seconds element
clsLabelString""Additional class for label element
clsButtonString""Additional class for buttons
clsOkButtonString""Additional class for OK button
clsCancelButtonString""Additional class for Cancel button
okButtonIconString"✓"Icon for OK button
cancelButtonIconString"𐄂"Icon for Cancel button
  • val([value]) - Gets or sets the current time as string (format: “HH:MM:SS”).
  • time([value]) - Gets or sets the current time as object with h, m, s properties.
  • date([value]) - Gets or sets the current time using Date object.
  • open() - Opens the time picker dropdown.
  • close() - Closes the time picker dropdown.
  • disable() - Disables the time picker component.
  • enable() - Enables the time picker component.
  • toggleState() - Toggles between enabled and disabled states.
  • destroy() - Destroys the component and returns the element to its original state.
// Get plugin instance
const timepicker = Metro.getPlugin('#my-timepicker', 'time-picker');
// Get current value
const currentValue = timepicker.val();
// Set new value
timepicker.val("14:30:00");
// Get time as object
const timeObj = timepicker.time(); // returns {h: 14, m: 30, s: 0}
// Set time from object
timepicker.time({h: 15, m: 45, s: 30});
// Get time as Date object
const dateObj = timepicker.date();
// Set time from Date object
const date = new Date();
date.setHours(10);
date.setMinutes(20);
timepicker.date(date);
// Open/close the picker
timepicker.open();
timepicker.close();
// Enable/disable the picker
timepicker.enable();
timepicker.disable();
EventArgumentsDescription
onSet{val, elementVal}Triggered when time is set
onOpen{val}Triggered when time picker is opened
onClose{val}Triggered when time picker is closed
onScroll{target, list, picker}Triggered when scrolling time lists
onTimePickerCreate{element}Triggered after time picker component creation

You can globally configure the time picker component using the Metro.timePickerSetup method:

Metro.timePickerSetup({
hoursStep: 2,
minutesStep: 5,
seconds: false,
showLabels: true
});
VariableDefaultDescription
--border-colorDepends on themeBorder color for various elements
--wheel-picker-border-radius4pxBorder radius for the time picker
--picker-font-sizeDepends on themeFont size for time elements
--datepicker-border-radius4pxBorder radius for action block
.my-custom-timepicker {
--wheel-picker-border-radius: 8px;
--picker-font-size: 1.2rem;
}
  • .time-picker - Main container class
  • .time-wrapper - Wrapper for time elements
  • .hours, .minutes, .seconds - Time part elements
  • .action-block - Container for action buttons
  • .button - Style for buttons
  • .show-labels - Shows labels for hours, minutes, seconds
  • .small, .medium, .large - Size modifiers affecting label positioning
  • .disabled - Disabled state for the time picker