TimeInput
TimeInput provides time input with support for 12-hour and 24-hour formats and configurable precision for hours, minutes, and seconds.
Key features:
- Time format support: 12-hour and 24-hour formats with customizable display
- Precision control: Configure precision for hours, minutes, and seconds
- Input validation: Real-time validation with visual feedback for invalid times
- Accessibility: Full keyboard navigation and screen reader support
- Localization: Automatic AM/PM labels based on user locale
Behaviors
This component supports the following behaviors:
| Behavior | Properties |
|---|---|
| Animation | animation, animationOptions |
| Bookmark | bookmark, bookmarkLevel, bookmarkTitle, bookmarkOmitFromToc |
| Form Binding | bindTo, initialValue, noSubmit |
| Component Label | label, labelPosition, labelWidth, labelBreak, required, enabled, shrinkToLabel, style, readOnly |
| Publish/Subscribe | subscribeToTopic |
| Tooltip | tooltip, tooltipMarkdown, tooltipOptions |
| Validation | bindTo, required, minLength, maxLength, lengthInvalidMessage, lengthInvalidSeverity, minValue, maxValue, rangeInvalidMessage, rangeInvalidSeverity, pattern, patternInvalidMessage, patternInvalidSeverity, regex, regexInvalidMessage, regexInvalidSeverity, validationMode, verboseValidationFeedback |
| Styling Variant | variant |
Properties
autoFocus
default: false
If this property is set to true, the component gets the focus automatically when displayed.
clearable
default: false
Whether to show a clear button that allows clearing the selected time
When enabled, it displays a clear button that allows users to clear the time input. Change the time value in this app and then click the clear button:
<App>
<TimeInput initialValue="11:30" />
<TimeInput clearable="true" initialValue="10:20" />
</App><App>
<TimeInput initialValue="11:30" />
<TimeInput clearable="true" initialValue="10:20" />
</App>clearIcon
The icon to display in the clear button.
<App>
<TimeInput initialValue="11:30" clearIcon="trash" />
</App><App>
<TimeInput initialValue="11:30" clearIcon="trash" />
</App>clearToInitialValue
default: false
Whether the clear button resets the time input to its initial value
emptyCharacter
default: "-"
Character to use as placeholder for empty time values. If longer than 1 character, uses the first character. Defaults to '-'
Character to use as placeholder for empty time values. If longer than 1 character, uses the first character. Defaults to '-'.
<App>
<TimeInput emptyCharacter="." />
<TimeInput emptyCharacter="*" />
<TimeInput emptyCharacter="abc" />
</App><App>
<TimeInput emptyCharacter="." />
<TimeInput emptyCharacter="*" />
<TimeInput emptyCharacter="abc" />
</App>enabled
default: true
This boolean property value indicates whether the component responds to user events (true) or not (false).
<App>
<TimeInput enabled="false" initialValue="14:30" />
</App> <App>
<TimeInput enabled="false" initialValue="14:30" />
</App> endIcon
This property sets an optional icon to appear on the end (right side when the left-to-right direction is set) of the input.
endText
This property sets an optional text to appear on the end (right side when the left-to-right direction is set) of the input.
gap
This property defines the gap between the adornments and the input area. If not set, the gap declared by the current theme is used.
hour24
default: true
Whether to use 24-hour format (true) or 12-hour format with AM/PM (false)
initialValue
This property sets the component's initial value.
<App>
<TimeInput initialValue="14:30:15" />
</App> <App>
<TimeInput initialValue="14:30:15" />
</App> maxTime
Maximum time that the user can select
minTime
Minimum time that the user can select
readOnly
default: false
Set this property to true to disallow changing the component value.
required
default: false
Whether the time input should be required
Marks the time input as required for form validation.
<App>
<TimeInput required="true" />
</App><App>
<TimeInput required="true" />
</App>seconds
default: false
Whether to show and allow input of seconds
startIcon
This property sets an optional icon to appear at the start (left side when the left-to-right direction is set) of the input.
startText
This property sets an optional text to appear at the start (left side when the left-to-right direction is set) of the input.
validationStatus
default: "none"
This property allows you to set the validation status of the input component.
Available values:
| Value | Description |
|---|---|
valid | Visual indicator for an input that is accepted |
warning | Visual indicator for an input that produced a warning |
error | Visual indicator for an input that produced an error |
| Value | Description |
|---|---|
valid | Visual indicator for an input that is accepted |
warning | Visual indicator for an input that produced a warning |
error | Visual indicator for an input that produced an error |
<App>
<TimeInput validationStatus="valid" initialValue="11:30" />
<TimeInput validationStatus="warning" initialValue="11:30" />
<TimeInput validationStatus="error" initialValue="11:30" />
</App><App>
<TimeInput validationStatus="valid" initialValue="11:30" />
<TimeInput validationStatus="warning" initialValue="11:30" />
<TimeInput validationStatus="error" initialValue="11:30" />
</App>Events
didChange
This event is triggered when value of TimeInput has changed.
Signature: didChange(newValue: any): void
newValue: The new value of the component.
Fired when the time value changes. Receives the new time value as a parameter.
The time value changes when the edited input part (hour, minute, second) loses focus or the AM/PM selectro changes.
<App var.selectedTime="No time selected">
<Text value="{selectedTime}" />
<TimeInput
format="h:m:s a"
initialValue="07:30:05"
onDidChange="(time) => selectedTime = time" />
</App><App var.selectedTime="No time selected">
<Text value="{selectedTime}" />
<TimeInput
format="h:m:s a"
initialValue="07:30:05"
onDidChange="(time) => selectedTime = time" />
</App>gotFocus
This event is triggered when the TimeInput has received the focus.
Signature: gotFocus(): void
Fired when the time picker receives focus.
<App var.isFocused="{false}">
<Text value="{isFocused
? 'TimeInput focused' : 'TimeInput lost focus'}"
/>
<TimeInput
format="HH:mm:ss a"
onGotFocus="isFocused = true"
onLostFocus="isFocused = false"
initialValue="14:30"
/>
</App><App var.isFocused="{false}">
<Text value="{isFocused
? 'TimeInput focused' : 'TimeInput lost focus'}"
/>
<TimeInput
format="HH:mm:ss a"
onGotFocus="isFocused = true"
onLostFocus="isFocused = false"
initialValue="14:30"
/>
</App>invalidTime
Fired when the user enters an invalid time
Signature: invalidTime(value: string): void
value: The invalid time value that was entered.
Fired when the user enters an invalid time value.
<App var.errorMessage="">
<Text value="{errorMessage}" />
<TimeInput
onInvalidTime="(error) => errorMessage = 'Invalid time entered'"
onDidChange="errorMessage = ''" />
</App><App var.errorMessage="">
<Text value="{errorMessage}" />
<TimeInput
onInvalidTime="(error) => errorMessage = 'Invalid time entered'"
onDidChange="errorMessage = ''" />
</App>lostFocus
This event is triggered when the TimeInput has lost the focus.
Signature: lostFocus(): void
Exposed Methods
focus
Focus the TimeInput component.
Signature: focus(): void
isoValue
Get the current time value formatted in ISO standard (HH:MM:SS) using 24-hour format, suitable for JSON serialization.
Signature: isoValue(): string | null
setValue
This method sets the current value of the TimeInput.
Signature: set value(value: any): void
value: The new time value to set for the time picker.
<App>
<HStack>
<Button
label="Set Time to 14:30"
onClick="picker.setValue('14:30')" />
<Button
label="Remove Time"
onClick="picker.setValue('')" />
</HStack>
<TimeInput id="picker" />
</App><App>
<HStack>
<Button
label="Set Time to 14:30"
onClick="picker.setValue('14:30')" />
<Button
label="Remove Time"
onClick="picker.setValue('')" />
</HStack>
<TimeInput id="picker" />
</App>value
You can query the component's value. If no value is set, it will retrieve undefined.
Signature: get value(): any
Parts
The component has some parts that can be styled through layout properties and theme variables separately:
ampm: The AM/PM indicator.clearButton: The button to clear the time input.hour: The hour input field.minute: The minute input field.second: The second input field.
Styling
Theme Variables
| Variable | Default Value (Light) | Default Value (Dark) |
|---|---|---|
| backgroundColor-input-TimeInput-invalid | rgba(220, 53, 69, 0.15) | rgba(220, 53, 69, 0.15) |
| backgroundColor-item-TimeInput--active | none | none |
| backgroundColor-item-TimeInput--hover | none | none |
| backgroundColor-menu-TimeInput | none | none |
| backgroundColor-TimeInput--default | none | none |
| backgroundColor-TimeInput--default--focus | none | none |
| backgroundColor-TimeInput--default--hover | none | none |
| backgroundColor-TimeInput--disabled | none | none |
| backgroundColor-TimeInput--error | none | none |
| backgroundColor-TimeInput--error--focus | none | none |
| backgroundColor-TimeInput--error--hover | none | none |
| backgroundColor-TimeInput--hover | none | none |
| backgroundColor-TimeInput--success | none | none |
| backgroundColor-TimeInput--success--focus | none | none |
| backgroundColor-TimeInput--success--hover | none | none |
| backgroundColor-TimeInput--warning | none | none |
| backgroundColor-TimeInput--warning--focus | none | none |
| backgroundColor-TimeInput--warning--hover | none | none |
| borderColor-menu-TimeInput | none | none |
| borderColor-TimeInput--default | none | none |
| borderColor-TimeInput--default--focus | none | none |
| borderColor-TimeInput--default--hover | none | none |
| borderColor-TimeInput--disabled | none | none |
| borderColor-TimeInput--error | none | none |
| borderColor-TimeInput--error--focus | none | none |
| borderColor-TimeInput--error--hover | none | none |
| borderColor-TimeInput--success | none | none |
| borderColor-TimeInput--success--focus | none | none |
| borderColor-TimeInput--success--hover | none | none |
| borderColor-TimeInput--warning | none | none |
| borderColor-TimeInput--warning--focus | none | none |
| borderColor-TimeInput--warning--hover | none | none |
| borderRadius-button-TimeInput | $borderRadius | $borderRadius |
| borderRadius-input-TimeInput | $borderRadius | $borderRadius |
| borderRadius-menu-TimeInput | none | none |
| borderRadius-TimeInput--default | none | none |
| borderRadius-TimeInput--error | none | none |
| borderRadius-TimeInput--success | none | none |
| borderRadius-TimeInput--warning | none | none |
| borderStyle-TimeInput--default | none | none |
| borderStyle-TimeInput--error | none | none |
| borderStyle-TimeInput--success | none | none |
| borderStyle-TimeInput--warning | none | none |
| borderWidth-TimeInput--default | none | none |
| borderWidth-TimeInput--error | none | none |
| borderWidth-TimeInput--success | none | none |
| borderWidth-TimeInput--warning | none | none |
| boxShadow-menu-TimeInput | none | none |
| boxShadow-TimeInput--default | none | none |
| boxShadow-TimeInput--default--focus | none | none |
| boxShadow-TimeInput--default--hover | none | none |
| boxShadow-TimeInput--error | none | none |
| boxShadow-TimeInput--error--focus | none | none |
| boxShadow-TimeInput--error--hover | none | none |
| boxShadow-TimeInput--success | none | none |
| boxShadow-TimeInput--success--focus | none | none |
| boxShadow-TimeInput--success--hover | none | none |
| boxShadow-TimeInput--warning | none | none |
| boxShadow-TimeInput--warning--focus | none | none |
| boxShadow-TimeInput--warning--hover | none | none |
| color-adornment-TimeInput--default | none | none |
| color-adornment-TimeInput--error | none | none |
| color-adornment-TimeInput--success | none | none |
| color-adornment-TimeInput--warning | none | none |
| color-divider-TimeInput | $textColor-secondary | $textColor-secondary |
| disabledColor-button-TimeInput | $textColor-disabled | $textColor-disabled |
| fontSize-ampm-TimeInput | inherit | inherit |
| fontSize-input-TimeInput | inherit | inherit |
| fontSize-TimeInput--default | none | none |
| fontSize-TimeInput--error | none | none |
| fontSize-TimeInput--success | none | none |
| fontSize-TimeInput--warning | none | none |
| gap-adornment-TimeInput | none | none |
| hoverColor-button-TimeInput | $color-surface-800 | $color-surface-800 |
| margin-icon-TimeInput | none | none |
| margin-input-TimeInput | none | none |
| maxHeight-menu-TimeInput | none | none |
| minWidth-ampm-TimeInput | 2.2em | 2.2em |
| minWidth-input-TimeInput | 0.54em | 0.54em |
| opacity-item-TimeInput--disabled | none | none |
| opacity-TimeInput--disabled | none | none |
| outlineColor-ampm-TimeInput--focused | none | none |
| outlineColor-button-TimeInput--focused | $color-accent-500 | $color-accent-500 |
| outlineColor-TimeInput--default--focus | none | none |
| outlineColor-TimeInput--error--focus | none | none |
| outlineColor-TimeInput--success--focus | none | none |
| outlineColor-TimeInput--warning--focus | none | none |
| outlineOffset-ampm-TimeInput--focused | none | none |
| outlineOffset-button-TimeInput--focused | 0 | 0 |
| outlineOffset-TimeInput--default--focus | none | none |
| outlineOffset-TimeInput--error--focus | none | none |
| outlineOffset-TimeInput--success--focus | none | none |
| outlineOffset-TimeInput--warning--focus | none | none |
| outlineStyle-TimeInput--default--focus | none | none |
| outlineStyle-TimeInput--error--focus | none | none |
| outlineStyle-TimeInput--success--focus | none | none |
| outlineStyle-TimeInput--warning--focus | none | none |
| outlineWidth-ampm-TimeInput--focused | none | none |
| outlineWidth-button-TimeInput--focused | 2px | 2px |
| outlineWidth-TimeInput--default--focus | none | none |
| outlineWidth-TimeInput--error--focus | none | none |
| outlineWidth-TimeInput--success--focus | none | none |
| outlineWidth-TimeInput--warning--focus | none | none |
| padding-button-TimeInput | 4px 4px | 4px 4px |
| padding-input-TimeInput | 0 2px | 0 2px |
| padding-item-TimeInput | none | none |
| padding-TimeInput | none | none |
| paddingBottom-TimeInput | none | none |
| paddingHorizontal-TimeInput | $space-2 | $space-2 |
| paddingLeft-TimeInput | none | none |
| paddingRight-TimeInput | none | none |
| paddingTop-TimeInput | none | none |
| paddingVertical-TimeInput | $space-2 | $space-2 |
| spacing-divider-TimeInput | 1px 0 | 1px 0 |
| textAlign-input-TimeInput | center | center |
| textColor-TimeInput--default | none | none |
| textColor-TimeInput--default--focus | none | none |
| textColor-TimeInput--default--hover | none | none |
| textColor-TimeInput--disabled | none | none |
| textColor-TimeInput--error | none | none |
| textColor-TimeInput--error--focus | none | none |
| textColor-TimeInput--error--hover | none | none |
| textColor-TimeInput--success | none | none |
| textColor-TimeInput--success--focus | none | none |
| textColor-TimeInput--success--hover | none | none |
| textColor-TimeInput--warning | none | none |
| textColor-TimeInput--warning--focus | none | none |
| textColor-TimeInput--warning--hover | none | none |
| transition-background-TimeInput | none | none |
| width-input-TimeInput | 1.8em | 1.8em |