TimeInput
Capture time or time range from user
Import
Source
Docs
Package
Usage
TimeInput component:
:
TimeRangeInput component (supports the same props as TimeInput component):
:
:
Controlled
With seconds
To add seconds set withSeconds prop:
:
:
12 hours format
:
Input props
:
Radius
xs
sm
md
lg
xl
Size
xs
sm
md
lg
xl
With icon
You can use any React node as icon:
:
Invalid state and error
:
:
It is not a valid time
Disabled state
:
:
Get input ref
You can get hours input ref with ref prop:
Accessibility
Provide hours, minutes and seconds labels to make inputs visible to screen reader:
TimeInput component props
| Name | Type | Description |
|---|---|---|
| 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 | Width<string | number> | Width of icon section in px |
| 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 |
| 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 | Width<string | 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
| Name | Type | Description |
|---|---|---|
| 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 | Width<string | number> | Width of icon section in px |
| 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 |
| 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 | Width<string | 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
| Name | Static selector | Description |
|---|---|---|
| controls | .mantine-TimeInput-controls | Wrapper around hours, minutes and seconds inputs |
| amPmInput | .mantine-TimeInput-amPmInput | AM/PM input |
| timeInput | .mantine-TimeInput-timeInput | Hours, minutes and seconds inputs |
| disabled | .mantine-TimeInput-disabled | Invalid disabled modifier |
| wrapper | .mantine-TimeInput-wrapper | Root Input element |
| invalid | .mantine-TimeInput-invalid | Invalid input modifier |
| icon | .mantine-TimeInput-icon | Input icon wrapper on the left side of the input, controlled by icon prop |
| withIcon | .mantine-TimeInput-withIcon | Input element styles when used with icon, controlled by icon prop |
| input | .mantine-TimeInput-input | Main input element |
| rightSection | .mantine-TimeInput-rightSection | Input right section, controlled by rightSection prop |
| root | .mantine-TimeInput-root | Root element |
| label | .mantine-TimeInput-label | Label element styles, defined by label prop |
| error | .mantine-TimeInput-error | Error element styles, defined by error prop |
| description | .mantine-TimeInput-description | Description element styles, defined by description prop |
| required | .mantine-TimeInput-required | Required asterisk element styles, defined by required prop |
TimeRangeInput component Styles API
| Name | Static selector | Description |
|---|---|---|
| controls | .mantine-TimeRangeInput-controls | Wrapper around hours, minutes and seconds inputs |
| amPmInput | .mantine-TimeRangeInput-amPmInput | AM/PM input |
| timeInput | .mantine-TimeRangeInput-timeInput | Hours, minutes and seconds inputs |
| disabled | .mantine-TimeRangeInput-disabled | Invalid disabled modifier |
| wrapper | .mantine-TimeRangeInput-wrapper | Root Input element |
| invalid | .mantine-TimeRangeInput-invalid | Invalid input modifier |
| icon | .mantine-TimeRangeInput-icon | Input icon wrapper on the left side of the input, controlled by icon prop |
| withIcon | .mantine-TimeRangeInput-withIcon | Input element styles when used with icon, controlled by icon prop |
| input | .mantine-TimeRangeInput-input | Main input element |
| rightSection | .mantine-TimeRangeInput-rightSection | Input right section, controlled by rightSection prop |
| root | .mantine-TimeRangeInput-root | Root element |
| label | .mantine-TimeRangeInput-label | Label element styles, defined by label prop |
| error | .mantine-TimeRangeInput-error | Error element styles, defined by error prop |
| description | .mantine-TimeRangeInput-description | Description element styles, defined by description prop |
| required | .mantine-TimeRangeInput-required | Required asterisk element styles, defined by required prop |