TimeInput

Capture time from the user
Import

Usage

TimeInput component is input[type="time"] with Input component styles:

Radius
xs
sm
md
lg
xl
Size
xs
sm
md
lg
xl
import { TimeInput } from '@mantine/dates';
function Demo() {
return (
<TimeInput
label="Current time"
withAsterisk
/>
);
}

Show browser picker

You can show browser picker by calling showPicker method of input element:

import { useRef } from 'react';
import { ActionIcon } from '@mantine/core';
import { TimeInput } from '@mantine/dates';
import { IconClock } from '@tabler/icons-react';
function Demo() {
const ref = useRef<HTMLInputElement>();
return (
<TimeInput
label="Click icon to show browser picker"
ref={ref}
rightSection={
<ActionIcon onClick={() => ref.current.showPicker()}>
<IconClock size="1rem" stroke={1.5} />
</ActionIcon>
}
maw={400}
mx="auto"
/>
);
}

With seconds

import { TimeInput } from '@mantine/dates';
function Demo() {
return <TimeInput withSeconds maw={400} mx="auto" />;
}

With icon

import { IconClock } from '@tabler/icons-react';
import { TimeInput } from '@mantine/dates';
function Demo() {
return <TimeInput icon={<IconClock size="1rem" stroke={1.5} />} maw={400} mx="auto" />;
}

Disabled state

import { IconClock } from '@tabler/icons-react';
import { TimeInput } from '@mantine/dates';
function Demo() {
return <TimeInput disabled />;
}

Accessibility

Provide aria-label in case you use component without label for screen reader support:

<TimeInput /> // -> not ok, input is not labeled
<TimeInput label="My input" /> // -> ok, input and label is connected
<TimeInput aria-label="My input" /> // -> ok, label is not visible but will be announced by screen reader

TimeInput component props

NameTypeDescription
description
ReactNode
Input description, displayed after label
descriptionProps
Record<string, any>
Props spread to description element
disabled
boolean
Disabled input state
error
ReactNode
Displays error message after input
errorProps
Record<string, any>
Props spread to error element
icon
ReactNode
Adds icon on the left side of input
iconWidth
Width<string | number>
Width of icon section
inputContainer
(children: ReactNode) => ReactNode
Input container component, defaults to React.Fragment
inputWrapperOrder
("input" | "label" | "error" | "description")[]
Controls order of the Input.Wrapper elements
label
ReactNode
Input label, displayed before input
labelProps
Record<string, any>
Props spread to label element
radius
number | "xs" | "sm" | "md" | "lg" | "xl"
Key of theme.radius or any valid CSS value to set border-radius, theme.defaultRadius by default
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
Width<string | number>
Width of right section, is used to calculate input padding-right
size
"xs" | "sm" | "md" | "lg" | "xl"
Input size
type
HTMLInputTypeAttribute
Input element type
variant
Variants<"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
Determines whether seconds input should be rendered
wrapperProps
Record<string, any>
Props passed to root element (InputWrapper component)

TimeInput component Styles API

NameStatic selectorDescription
wrapper.mantine-TimeInput-wrapperRoot Input element
icon.mantine-TimeInput-iconInput icon wrapper on the left side of the input, 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