Timepicker
React Bootstrap 5 Timepicker component
Use MDB custom Timepicker component to select time.
Note: Read the API tab to find all available options and advanced customization
Basic example
MDB allows us to automatically initialize a Timepicker when the page is loaded.
Inline Timepicker with 12h
MDBTimepicker allows you to use a inline version timepicker. Default version is with 12h.
Inline Timepicker with 24h
MDB Timepicker allows you to use a inline version timepicker. You have to add options
format24
to true.
Custom Icon
You can set your custom icon to input. If you will add the icon, the main icon from the input will be replaced with yours.
With icon
Without icon
MDBTimepicker allows to set input without icon.
Default time
MDB Timepicker allows to initialize a default time in the picker and input. You can set it
with option defaultTime
. This options accepts strings like:
- 12:34
- 12:34 PM
- 12:34 AM
and also new Date() format like:
- new Date()
- new Date().toLocaleTimeString([],{timeStyle: 'short'})
Note: If you are using string with PM/AM, you have to have option format24 set to false otherwise your default time will be formate to 24h. Also if you are using string without PM/AM and you would like have 24h format hour you have to set option format24 to true. If you will only put a string without PM/AM and format24 set to false you are gonna have a timepicker with 12h and format set to AM with default.
Handle input value
If you want handle input value on modal approve, you have to add custom event to selected picker.
Format 24h
Timepicker allows you to use time format with 24 hours. You can set it with the format="24h"
property.
Just Input
You can set a timepicker to just an input.
Increment
You can set a increment value by 5 to a minutes.
Max time
You can max time to timepicker with options.
Max time with PM
You can max time to timepicker with options.
Max time with AM
You can max time to timepicker with options.
Min time
You can min time to timepicker with options.
Min time with PM
You can min time to timepicker with options.
Min time with AM
You can min time to timepicker with options.
Max/Min hours
You can max and min hour to timepicker with options.
Maximum hour
You can set only maximum hour to timepicker.
Minimum hour
You can set only minimum hour to timepicker.
Disable past
Use the disablePast
option to disallow past time selection.
Disable future
Use the disableFuture
option to disallow future time selection.
Accessibility
We added proper aria attributes to the timepicker controls to make the component accessible. It's possible to change the values of those attributes by modyfing the component options:
Timepicker - API
Import
Properties
MDBTimepicker
Name | Type | Default | Description | Example |
---|---|---|---|---|
amLabel
|
string | 'AM' |
Allows to set custom text to the AM button |
<MDBTimepicker amLabel='Ante Meridiem' />
|
pmLabel
|
string | 'PM' |
Allows to set custom text to the PM button |
<MDBTimepicker pmLabel='Post Meridiem' />
|
bodyId
|
string | '' |
Set the ID to the Timepicker's body. |
<MDBTimepicker bodyId='bodyID' />
|
headId
|
string | '' |
Set the ID to the Timepicker's head. |
<MDBTimepicker headId='headID' />
|
btnIcon
|
boolean | 'true' |
Appends an icon as a button. Set it to false to keep icon only. |
<MDBTimepicker btnIcon={false} />
|
cancelLabel
|
string | 'Cancel' |
Changes a cancel button label |
<MDBTimepicker cancelLabel='Close' />
|
clearLabel
|
string | 'Clear' |
Changes a clear button label |
<MDBTimepicker clearLabel='Clear a picker' />
|
customIcon
|
string | '' |
Sets a custom icon. You have to provide an icon type as well (i.e. "far", "fas", "fab" |
<MDBTimepicker customIcon='fab fa-react' />
|
customIconSize
|
string | '' |
Sets a size for the custom icon |
<MDBTimepicker customIcon='fab fa-react' customIconSize='2x' />
|
customValue
|
string | '' |
Custom value to control the input |
<MDBTimepicker customIcon='fab fa-react' customValue={value} />
|
defaultValue
|
string | date | '' |
Sets picker default value |
<MDBTimepicker defaultValue="12:33 AM" />
|
disabled
|
boolean | false |
Disables picker |
<MDBTimepicker disabled />
|
disableFuture
|
boolean | false |
Disallows future time selection |
<MDBTimepicker disableFuture />
|
disablePast
|
boolean | false |
Disallows past time selection |
<MDBTimepicker disablePast />
|
format
|
"12h" | "24h" | '12h' |
Sets a format for the picker |
<MDBTimepicker format='24h' />
|
inline
|
boolean | 'false' |
Changes a picker into inline version |
<MDBTimepicker inline />
|
increment
|
boolean | 'false' |
Increment minutes by 5 |
<MDBTimepicker increment />
|
inputWrapperTag
|
string | 'span' |
Defines tag of the MDBTimepicker input wrapper element |
<MDBTimepicker inputWrapperTag="span" />
|
inputID
|
string | '' |
Sets an ID for the input |
<MDBTimepicker inputID='customID' />
|
inputClasses
|
string | '' |
Add custom class to input |
<MDBTimepicker inputClasses='test' />
|
inputLabel
|
string | 'Select a time' |
Changes an input label |
<MDBTimepicker inputLabel='Pick a time' />
|
invalidLabel
|
string | 'Invalid Time Format' |
Changes an invalid feedback label |
<MDBTimepicker invalidLabel='Provide a correct time' />
|
justInput
|
boolean | 'false' |
Opens a timepicker after clicking on input |
<MDBTimepicker inputID='customID' />
|
minHour
|
number | '' |
Sets picker minimum hour |
<MDBTimepicker minHour={8} />
|
maxHour
|
number | '' |
Sets picker maximum hour |
<MDBTimepicker maxHour={10} />
|
minTime
|
string | '' |
Sets picker minimum time |
<MDBTimepicker minTime='06:07 AM' />
|
maxTime
|
string | '' |
Sets picker maximum time |
<MDBTimepicker maxTime='09:07 AM' />
|
noIcon
|
boolean | 'false' |
Removes icon from picker input |
<MDBTimepicker noIcon />
|
openRef
|
React.RefObject | '' |
Reference to the custom toggle element |
<MDBTimepicker openRef={customRef} />
|
submitLabel
|
string | 'Ok' |
Changes a submit button label |
<MDBTimepicker submitLabel='Submit' />
|
switchHoursToMinutesOnClick
|
boolean | true |
Allows to enable/disable switching to minutes if hours are selected |
<MDBTimepicker switchHoursToMinutesOnClick={true} />
|
timePickerClasses
|
string | '' |
Sets custom classes to the picker modal element |
<MDBTimepicker timePickerClasses='bg-danger' />
|
Events
Name | Type | Description |
---|---|---|
onChange
|
(value: string) => void | Returns string value on input change |
onOpen
|
() => void | Executed when the timepicker is opened |
onClose
|
() => void | Executed when the timepicker is closed |
CSS variables
As part of MDB’s evolving CSS variables approach, timepicker now use local CSS variables for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.
Timepicker CSS variables are in different classes which belong to this component. To make it easier to use them, you can find below all of the used CSS variables.