Basic TimePicker
TimePicker Variants
Standard TimePicker
Default clock face for time selection
Compact TimePicker
Smaller, more condensed time picker
Vertical Orientation
Default layout optimized for mobile
Horizontal Orientation
Landscape layout for desktop
The TimePicker component supports different variants to suit different use cases:
- Standard TimePicker: Uses a clock face interface for intuitive time selection with regular size.
- Compact TimePicker: Smaller variant good for space-constrained interfaces.
- Vertical Orientation: Compact layout with clock below time display, best for mobile devices.
- Horizontal Orientation: Wider layout with clock beside time display, optimized for desktop views.
Time Formats
12-Hour Format (AM/PM)
Standard time format with AM/PM indicator
24-Hour Format
Military time format without AM/PM
12-Hour Format with Seconds
AM/PM format with precise seconds
24-Hour Format with Seconds
Military time with seconds for precise timing
The TimePicker component supports different time formats to match your application's needs:
- 12-Hour Format (AM/PM): Common in the US and some other countries, uses AM/PM indicators.
- 24-Hour Format (Military): Common internationally, eliminates AM/PM confusion.
- Seconds Display: Optional seconds for precise time entry, useful for scheduling systems.
You can customize the format using the format
and showSeconds
properties:
const timePicker = createTimePicker({ format: TIME_FORMAT.FORMAT_24, // Use 24-hour format showSeconds: true // Show seconds selector });
Time Constraints
Business Hours
Restrict selection to business hours (9:00 AM - 5:00 PM)
Appointment Slots
15-minute intervals for appointment scheduling
Delivery Time Slots
Morning (8-12), Afternoon (12-5), Evening (5-9)
Time constraints can be applied in different ways:
- Using the
minTime
property to prevent selection before a certain time - Using the
maxTime
property to prevent selection after a certain time - Using the
minuteStep
property to restrict minutes to specific intervals (e.g., 15-minute slots) - Using the
secondStep
property for second intervals when seconds are displayed
Time constraints are useful for:
- Restricting selection to business hours
- Creating appointment slots
- Setting up delivery windows
- Creating predefined time ranges
Invalid times that fall outside constraints will be automatically adjusted to the nearest valid time.
Programmatic Control
Event Log
Available API Methods:
timePicker.setValue(time)
: Sets the selected time (format: 'HH:MM' or 'HH:MM:SS')timePicker.getValue()
: Gets the current time value as a stringtimePicker.getTimeObject()
: Gets the time as an object with hours, minutes, seconds, and periodtimePicker.open()
: Opens the time pickertimePicker.close()
: Closes the time pickertimePicker.toggle()
: Toggles the time picker open/closed statetimePicker.setType(type)
: Sets the picker type (DIAL or INPUT)timePicker.getType()
: Gets the current picker typetimePicker.setFormat(format)
: Sets the time format (AMPM or MILITARY)timePicker.getFormat()
: Gets the current formattimePicker.on(event, handler)
: Adds an event listenertimePicker.off(event, handler)
: Removes an event listener
Available Events:
change
: Fired when the selected time changesopen
: Fired when the time picker opensclose
: Fired when the time picker closesconfirm
: Fired when the user confirms a time selectioncancel
: Fired when the user cancels time selection
Customized TimePickers
Custom Button Text
Customized text for action buttons
Custom Icons
Custom icons for clock and keyboard buttons
Custom Container
TimePicker mounted in a specific container
This TimePicker will open inline in this container
Customizing TimePickers
The TimePicker component offers several customization options:
1. Custom Text and Labels
const timePicker = createTimePicker({ title: 'Schedule Your Call', // Custom title cancelText: 'Dismiss', // Custom cancel button text confirmText: 'Schedule' // Custom confirm button text });
2. Custom Icons
const timePicker = createTimePicker({ clockIcon: '<svg>...</svg>', // Custom clock icon SVG keyboardIcon: '<svg>...</svg>' // Custom keyboard icon SVG });
3. Custom Container
const timePicker = createTimePicker({ container: document.getElementById('my-container'), // Custom container element isOpen: true // Start open when using a custom container for inline display });
4. CSS Customization
You can customize the appearance further using CSS:
/* Custom time picker styling */ .mtrl-time-picker-dialog { --mtrl-primary: #0088ff; --mtrl-on-primary: #ffffff; /* Custom shadows */ box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2); } /* Custom dial styling */ .mtrl-time-picker-dial-face { background-color: #f0f8ff; }