TimeInput

Capture time or time range from user
Import

Usage

TimeInput component:

:
import { TimeInput } from '@mantine/dates';
function Demo() {
return <TimeInput label="What time is it now?" />;
}

TimeRangeInput component (supports the same props as TimeInput component):

:
:
import dayjs from 'dayjs';
import { useState } from 'react';
import { TimeRangeInput } from '@mantine/dates';
function Demo() {
const now = new Date();
const then = dayjs(now).add(30, 'minutes').toDate();
const [value, setValue] = useState<[Date, Date]>([now, then]);
return <TimeRangeInput label="Appointment time" value={value} onChange={setValue} clearable />;
}

Controlled

import { useState } from 'react';
import { TimeInput } from '@mantine/dates';
function Demo() {
const [value, onChange] = useState(new Date());
return <TimeInput value={value} onChange={onChange} />;
}

With seconds

To add seconds set withSeconds prop:

:
:
import { TimeInput } from '@mantine/dates';
function Demo() {
return <TimeInput label="What time is it now?" withSeconds defaultValue={new Date()} />;
}

12 hours format

:
import { TimeInput } from '@mantine/dates';
function Demo() {
return <TimeInput label="Pick time" format="12" defaultValue={new Date()} />;
}

Input props

:
Radius
xs
sm
md
lg
xl
Size
xs
sm
md
lg
xl
import { TimeInput } from '@mantine/dates';
function Demo() {
return (
<TimeInput
defaultValue={new Date()}
label="Pick time"
amLabel="am"
pmLabel="pm"
withAsterisk
/>
);
}

With icon

You can use any React node as icon:

Download more icon variants from https://tabler-icons.io/i/clock
:
import { TimeInput } from '@mantine/dates';
import { IconClock } from '@tabler/icons';
function Demo() {
return (
<TimeInput
label="Pick time"
placeholder="Pick time"
icon={<IconClock size={16} />}
defaultValue={new Date()}
/>
);
}

Invalid state and error

:
:
// Error as boolean – red border color
<TimeInput error />
// Error as React node – red border color and message below input
<TimeInput error="It is not a valid time" />

Disabled state

:
:
import { TimeInput } from '@mantine/dates';
function Demo() {
return <TimeInput disabled />;
}

Get input ref

You can get hours input ref with ref prop:

import { useRef } from 'react';
import { TimeInput } from '@mantine/dates';
function Demo() {
const inputRef = useRef<HTMLInputElement>(null);
return <TimeInput ref={inputRef} />;
}

Accessibility

Provide hours, minutes and seconds labels to make inputs visible to screen reader:

<TimeInput hoursLabel="Hours" minutesLabel="Minutes" secondsLabel="Seconds" />
Download more icon variants from https://tabler-icons.io/i/search

TimeInput component props

NameTypeDescription
amLabel
string
Label for 'am'
amPmLabel
string
aria-label for am/pm input
amPmPlaceholder
string
Placeholder for am/pm input
clearButtonLabel
string
aria-label for clear button
clearable
boolean
Allow to clear item
defaultValue
Date
Uncontrolled input default value
description
ReactNode
Input description, displayed after label
descriptionProps
Record<string, any>
Props spread to description element
disabled
boolean
Disable field
error
ReactNode
Displays error message after input
errorProps
Record<string, any>
Props spread to error element
format
"12" | "24"
Time format
hoursLabel
string
aria-label for hours input
icon
ReactNode
Adds icon on the left side of input
iconWidth
number
Width of icon section in px
inputContainer
(children: ReactNode) => ReactNode
Input container component, defaults to React.Fragment
inputWrapperOrder
("input" | "label" | "description" | "error")[]
Controls order of the Input.Wrapper elements
label
ReactNode
Input label, displayed before input
labelProps
Record<string, any>
Props spread to label element
minutesLabel
string
aria-label for minutes input
name
string
Uncontrolled input name
nextRef
RefObject<HTMLInputElement>
Ref to focus after final TimeInput field. Used by TimeRangeInput
onChange
(value: Date) => void
Controlled input onChange handler
pmLabel
string
Label for 'pm'
radius
number | "xs" | "sm" | "md" | "lg" | "xl"
Input border-radius from theme or number to set border-radius in px
required
boolean
Sets required on input element
rightSection
ReactNode
Right section of input, similar to icon but on the right
rightSectionProps
Record<string, any>
Props spread to rightSection div element
rightSectionWidth
number
Width of right section, is used to calculate input padding-right
secondsLabel
string
aria-label for seconds input
size
"xs" | "sm" | "md" | "lg" | "xl"
Input size
timePlaceholder
string
Placeholder for hours/minutes/seconds inputs
value
Date
Controlled input value
variant
"unstyled" | "default" | "filled"
Defines input appearance, defaults to default in light color scheme and filled in dark
withAsterisk
boolean
Determines whether required asterisk should be rendered, overrides required prop, does not add required attribute to the input
withSeconds
boolean
Display seconds input
wrapperProps
Record<string, any>
Properties spread to root element

TimeRangeInput component props

NameTypeDescription
amPmLabel
string
aria-label for am/pm input
amPmPlaceholder
string
placeholder for am/pm input
clearButtonLabel
string
aria-label for clear button
clearable
boolean
Allow to clear item
defaultValue
[Date, Date]
Uncontrolled input default value
description
ReactNode
Input description, displayed after label
descriptionProps
Record<string, any>
Props spread to description element
disabled
boolean
Disable field
error
ReactNode
Displays error message after input
errorProps
Record<string, any>
Props spread to error element
format
"12" | "24"
The time format
hoursLabel
string
aria-label for hours input
icon
ReactNode
Adds icon on the left side of input
iconWidth
number
Width of icon section in px
inputContainer
(children: ReactNode) => ReactNode
Input container component, defaults to React.Fragment
inputWrapperOrder
("input" | "label" | "description" | "error")[]
Controls order of the Input.Wrapper elements
label
ReactNode
Input label, displayed before input
labelProps
Record<string, any>
Props spread to label element
labelSeparator
string
Separator between time inputs
minutesLabel
string
aria-label for minutes input
name
string
Uncontrolled input name
onChange
(value: [Date, Date]) => void
Controlled input onChange handler
radius
number | "xs" | "sm" | "md" | "lg" | "xl"
Input border-radius from theme or number to set border-radius in px
required
boolean
Sets required on input element
rightSection
ReactNode
Right section of input, similar to icon but on the right
rightSectionProps
Record<string, any>
Props spread to rightSection div element
rightSectionWidth
number
Width of right section, is used to calculate input padding-right
secondsLabel
string
aria-label for seconds input
size
"xs" | "sm" | "md" | "lg" | "xl"
Input size
timePlaceholder
string
placeholder for time input
value
[Date, Date]
Controlled input value
variant
"unstyled" | "default" | "filled"
Defines input appearance, defaults to default in light color scheme and filled in dark
withAsterisk
boolean
Determines whether required asterisk should be rendered, overrides required prop, does not add required attribute to the input
withSeconds
boolean
Display seconds input
wrapperProps
Record<string, any>
Properties spread to root element

TimeInput component Styles API

NameStatic selectorDescription
controls.mantine-TimeInput-controlsWrapper around hours, minutes and seconds inputs
amPmInput.mantine-TimeInput-amPmInputAM/PM input
timeInput.mantine-TimeInput-timeInputHours, minutes and seconds inputs
disabled.mantine-TimeInput-disabledInvalid disabled modifier
wrapper.mantine-TimeInput-wrapperRoot Input element
invalid.mantine-TimeInput-invalidInvalid input modifier
icon.mantine-TimeInput-iconInput icon wrapper on the left side of the input, controlled by icon prop
withIcon.mantine-TimeInput-withIconInput element styles when used with icon, controlled by icon prop
input.mantine-TimeInput-inputMain input element
rightSection.mantine-TimeInput-rightSectionInput right section, controlled by rightSection prop
root.mantine-TimeInput-rootRoot element
label.mantine-TimeInput-labelLabel element styles, defined by label prop
error.mantine-TimeInput-errorError element styles, defined by error prop
description.mantine-TimeInput-descriptionDescription element styles, defined by description prop
required.mantine-TimeInput-requiredRequired asterisk element styles, defined by required prop

TimeRangeInput component Styles API

NameStatic selectorDescription
controls.mantine-TimeRangeInput-controlsWrapper around hours, minutes and seconds inputs
amPmInput.mantine-TimeRangeInput-amPmInputAM/PM input
timeInput.mantine-TimeRangeInput-timeInputHours, minutes and seconds inputs
disabled.mantine-TimeRangeInput-disabledInvalid disabled modifier
wrapper.mantine-TimeRangeInput-wrapperRoot Input element
invalid.mantine-TimeRangeInput-invalidInvalid input modifier
icon.mantine-TimeRangeInput-iconInput icon wrapper on the left side of the input, controlled by icon prop
withIcon.mantine-TimeRangeInput-withIconInput element styles when used with icon, controlled by icon prop
input.mantine-TimeRangeInput-inputMain input element
rightSection.mantine-TimeRangeInput-rightSectionInput right section, controlled by rightSection prop
root.mantine-TimeRangeInput-rootRoot element
label.mantine-TimeRangeInput-labelLabel element styles, defined by label prop
error.mantine-TimeRangeInput-errorError element styles, defined by error prop
description.mantine-TimeRangeInput-descriptionDescription element styles, defined by description prop
required.mantine-TimeRangeInput-requiredRequired asterisk element styles, defined by required prop