Time input
Time input
Component demo
Interactive example
<ic-time-inputlabel="What time would you like to collect your coffee?"></ic-time-input>
Time input details
Props
All components also accept native properties supported by the DOM, such asclassName
and
style
.
|
|
|
---|---|---|
|
The label for the time input. |
|
|
An array of times that will be disabled in the time input. The times can be in any format supported as |
|
|
If |
|
|
If |
|
|
The helper text that will be displayed for additional field guidance. This will default to the text "Use format" along with the |
|
|
If |
|
|
If |
|
|
The ID for the input. |
ic-time-input-${inputIds++}
|
|
The text to display as the validation message when an invalid time is entered. |
|
|
The latest time that will be allowed. The value can be in any format supported as |
|
|
The earliest time that will be allowed. The value can be in any format supported as |
|
|
The name of the control, which is submitted with the form data. |
|
|
If |
|
|
If |
|
|
The size of the time input to be displayed. |
|
|
Sets the time picker to the dark or light theme colors. "inherit" will set the color based on the system settings or ic-theme component. |
|
|
The format in which the time will be displayed. |
|
|
The time period format: "12" for 12-hour, "24" for 24-hour. Defaults to "24". |
|
|
The validation status - e.g. 'error' | 'warning' | 'success'. This will override the built-in time validation. |
|
|
The text to display as the validation message. This will override the built-in time validation. |
|
|
The value of the time input. The value can be in any format supported as |
|
The label for the time input. |
An array of times that will be disabled in the time input. The times can be in any format supported as |
If |
If |
The helper text that will be displayed for additional field guidance. This will default to the text "Use format" along with the |
If |
If |
The ID for the input. ic-time-input-${inputIds++}
|
The text to display as the validation message when an invalid time is entered. |
The latest time that will be allowed. The value can be in any format supported as |
The earliest time that will be allowed. The value can be in any format supported as |
The name of the control, which is submitted with the form data. |
If |
If |
The size of the time input to be displayed. |
Sets the time picker to the dark or light theme colors. "inherit" will set the color based on the system settings or ic-theme component. |
The format in which the time will be displayed. |
The time period format: "12" for 12-hour, "24" for 24-hour. Defaults to "24". |
The validation status - e.g. 'error' | 'warning' | 'success'. This will override the built-in time validation. |
The text to display as the validation message. This will override the built-in time validation. |
The value of the time input. The value can be in any format supported as |
Slots
A slot allows for any type of element or markup to be passed into and rendered within a web component. This creates more flexibility than using a prop which must take a specific type of data.
Content can be slotted into a component by adding it as a top-level child of the component.
Slots can have a name to identify them. These specify which slot the content will be inserted into, and therefore where it will be rendered and how it will be used within the component. The name of the slot to be used can be specified by passing it via a
slot
attribute on the slotted content.
|
|
---|---|
|
|
|
Events
All components also accept native events supported by the DOM, such as
onClick
and
onKeyDown
.
|
|
|
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Methods
|
|
|
---|---|---|
|
|
|
|
Variants
With values
String
Interactive example
<ic-time-inputlabel="What time would you like to collect your coffee?"value="13:45:00"></ic-time-input>
Date object
Interactive example
<ic-time-inputid="time-input-default-time-date"label="What time would you like to collect your coffee?"></ic-time-input>
Zulu time
Interactive example
<ic-time-inputlabel="What time would you like to collect your coffee?"></ic-time-input>
Required
To set the time input as a required field, set therequired
prop totrue
. This will add an asterisk at the end of the time input label.
Interactive example
<ic-time-inputlabel="What time would you like to collect your coffee?"required="true"></ic-time-input>
IcChange event
Retrieving the time input value viaIcChange
returns the time as a Date object.
The event returns the Date object once hour, minute and second have been entered.
Interactive example
<ic-time-inputlabel="What time would you like to collect your coffee?"></ic-time-input>
IcChange with emitTimePartChange
When theemitTimePartChange
prop is set totrue
, theIcChange
event will be emitted anytime part of the time input changes (i.e. any change to the hour, minute or second).
Interactive example
<ic-time-inputemit-time-part-change="true"label="What time would you like to collect your coffee?"></ic-time-input>
Hide label
To hide the label, set thehideLabel
prop totrue
. The requiredlabel
will still be read out by screen readers.
Interactive example
<ic-time-inputlabel="What time would you like to collect your coffee?"hide-label="true"></ic-time-input>
Disabled
Set thedisabled
prop totrue
to prevent interaction with the time input.
Interactive example
<ic-time-inputlabel="What time would you like to collect your coffee?"disabled="true"></ic-time-input>
Sizes
Interactive example
<ic-time-inputlabel="What time would you like to collect your coffee?"size="small"></ic-time-input><ic-time-inputlabel="What time would you like to collect your coffee?"></ic-time-input><ic-time-inputlabel="What time would you like to collect your coffee?"size="large"></ic-time-input>
Custom helper text
Use the helper text to add additional detail for the time input. Display custom content using thehelper-text
slot.
Interactive example
<ic-time-inputlabel="What time would you like to collect your coffee?"helper-text="We will have your order ready for you at this time"></ic-time-input><ic-time-inputlabel="What time would you like to collect your coffee?"><ic-typographyvariant="caption"slot="helper-text"><span> For special requests, <ic-linkhref="#">contact us</ic-link> before choosing a time</span></ic-typography></ic-time-input>
Hide helper text
Interactive example
<ic-time-inputlabel="What time would you like to collect your coffee?"helper-text="We will have your order ready for you at this time"hide-helper-text="true"></ic-time-input>
Custom validation
Validation on time input is set via thevalidationStatus
andvalidationText
props.
validationStatus
will set the style of the validation message.validationStatus
accepts:
-
error
-
warning
-
success
validationStatus
is required for thevalidationText
to appear.
Interactive example
<ic-time-inputlabel="What time would you like to collect your coffee?"validation-status="error"validation-text="There is a coffee shortage forecast for that time. Please choose a different time."></ic-time-input><ic-time-inputlabel="What time would you like to collect your coffee?"validation-status="warning"validation-text="Please be aware that there may be a coffee shortage at that time."></ic-time-input><ic-time-inputlabel="What time would you like to collect your coffee?"validation-status="success"validation-text="Your coffee will be available for you to collect at this time."></ic-time-input>
Disabled times
To disable specific times in the time input, set thedisableTimes
prop. ThedisableTimes
prop accepts an array of time objects or strings. Each time object can have astart
andend
property to define a range of disabled times, or it can be a single time string to disable that specific time. The time can be in any format supported astimeFormat
, in ISO 8601 time string format (HH:MM:SS) or as a JavaScript Date object.
Interactive example
<ic-time-inputid="time-input-default-disable-time"label="What time would you like to collect your coffee?"></ic-time-input>
Time period
Interactive example
<ic-time-inputlabel="What time would you like to collect your coffee?"time-period="12"></ic-time-input>
Time format (HH:MM)
Interactive example
<ic-time-inputlabel="What time would you like to collect your coffee?"time-format="HH:MM"></ic-time-input>
Min and max
It is possible to set a minimum and maximum time range using themin
andmax
props. If a time is set and it is earlier the minimum or later the maximum time, a validation error will appear.
Themin
andmax
props accept the same time formats as thevalue
prop.
Interactive example
<ic-time-inputlabel="What time would you like to collect your coffee?"min="08:00:00"max="16:00:00"></ic-time-input>
Form
Interactive example
<formclass="parent-form"><ic-time-inputlabel="What time would you like to collect your coffee?"value="13:45:00"></ic-time-input><divclass="button-container"><ic-buttontype="submit"value="Submit"></ic-button><ic-buttontype="reset"value="Reset"></ic-button></div></form>
With clearing value
The time input can be cleared by setting thevalue
attribute to one of the following:
-
empty string
-
null
-
undefined
Interactive example
<ic-time-inputid="time-input-clear-value"label="What time would you like to collect your coffee?"value="08:30:00"></ic-time-input><divclass="button-container"><ic-buttonid="update">Update date</ic-button><ic-buttonid="null-btn">Set null</ic-button><ic-buttonid="empty-btn">Set empty string</ic-button><ic-buttonid="undef-btn">Set undefined</ic-button></div>