Date input
Date input
Component demo
Interactive example
<ic-date-inputlabel="When would you like to collect your coffee?"></ic-date-input>
Date input details
Props
All components also accept native properties supported by the DOM, such asclassName
and
style
.
|
|
|
---|---|---|
|
The label for the date input. |
|
|
The format in which the date will be displayed. |
|
|
The days of the week to disable. |
|
|
The text to display as the validation message when |
|
|
If |
|
|
The text to display as the validation message when |
|
|
If |
|
|
The text to display as the validation message when |
|
|
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-date-input-${inputIds++}
|
|
The text to display as the validation message when an invalid date is entered. |
|
|
The latest date that will be allowed. The value can be in any format supported as |
|
|
The earliest date 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 date input to be displayed. |
|
|
Sets the date picker to the dark or light theme colors. "inherit" will set the color based on the system settings or ic-theme component. |
|
|
The validation status - e.g. 'error' | 'warning' | 'success'. This will override the built-in date validation. |
|
|
The text to display as the validation message. This will override the built-in date validation. |
|
|
The value of the date input. The value can be in any format supported as |
|
The label for the date input. |
The format in which the date will be displayed. |
The days of the week to disable. |
The text to display as the validation message when |
If |
The text to display as the validation message when |
If |
The text to display as the validation message when |
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-date-input-${inputIds++}
|
The text to display as the validation message when an invalid date is entered. |
The latest date that will be allowed. The value can be in any format supported as |
The earliest date 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 date input to be displayed. |
Sets the date picker to the dark or light theme colors. "inherit" will set the color based on the system settings or ic-theme component. |
The validation status - e.g. 'error' | 'warning' | 'success'. This will override the built-in date validation. |
The text to display as the validation message. This will override the built-in date validation. |
The value of the date 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-date-inputlabel="When would you like to collect your coffee?"value="21/01/2001"></ic-date-input>
Date object
Interactive example
<ic-date-inputlabel="When would you like to collect your coffee?"></ic-date-input>
Zulu datetime
Interactive example
<ic-date-inputlabel="When would you like to collect your coffee?"></ic-date-input>
String with hyphens
Interactive example
<ic-date-inputlabel="When would you like to collect your coffee?"></ic-date-input>
Epoch date
Interactive example
<ic-date-inputlabel="When would you like to collect your coffee?"></ic-date-input>
Required
To set the date input as a required field, set therequired
prop totrue
. This will add an asterisk at the end of the date input label.
Interactive example
<ic-date-inputlabel="When would you like to collect your coffee?"required="true"></ic-date-input>
Hide label
To hide the label, set thehideLabel
prop totrue
. The requiredlabel
will still be read out by screen readers.
Interactive example
<ic-date-inputlabel="When would you like to collect your coffee?"hide-label="true"></ic-date-input>
Disabled
Set thedisabled
prop totrue
to prevent interaction with the date input.
Interactive example
<ic-date-inputlabel="When would you like to collect your coffee?"disabled="true"></ic-date-input>
Sizes
Interactive example
<ic-date-inputlabel="When would you like to collect your coffee?"size="small"></ic-date-input><ic-date-inputlabel="When would you like to collect your coffee?"></ic-date-input><ic-date-inputlabel="When would you like to collect your coffee?"size="large"></ic-date-input>
Custom helper text
Use the helper text to add additional detail for the date input. Display custom content using thehelper-text
slot.
Interactive example
<ic-date-inputlabel="When would you like to collect your coffee?"helper-text="We will have your order ready for you on this date"></ic-date-input>
Hide helper text
Interactive example
<ic-date-inputlabel="When would you like to collect your coffee?"helper-text="We will have your order ready for you on this date"hide-helper-text="true"></ic-date-input>
Custom validation
Validation on date 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-date-inputlabel="When would you like to collect your coffee?"validation-status="error"validation-text="There is a coffee shortage forecast for that day. Please choose a different date."></ic-date-input><ic-date-inputlabel="When would you like to collect your coffee?"validation-status="warning"validation-text="Please be aware that there may be a coffee shortage on that day."></ic-date-input><ic-date-inputlabel="When would you like to collect your coffee?"validation-status="success"validation-text="Your coffee will be available for you to collect on this day."></ic-date-input>
Disabled past dates
Validation can be set on the date input if a date in the past has been set by setting thedisablePast
prop totrue
.
Enter a date in the past to view the validation message:
Interactive example
<ic-date-inputlabel="When would you like to collect your coffee?"disable-past="true"></ic-date-input>
Disabled future dates
Validation can be set on the date input if a date in the future has been set by setting thedisableFuture
prop totrue
.
Enter a date in the future to view the validation message:
Interactive example
<ic-date-inputlabel="When would you like to collect your coffee?"disable-future="true"></ic-date-input>
Min and max
It is possible to set a minimum and maximum date range using themin
andmax
props. If a date is set and it is before the minimum or after the maximum date, a validation error will appear.
Themin
andmax
props accept the same date formats as thevalue
prop.
Interactive example
<ic-date-inputlabel="When would you like to collect your coffee?"min="02/01/2023"max="20-07-2023"></ic-date-input>
Form
Interactive example
<form><ic-date-inputlabel="When would you like to collect your coffee?"value="13/03/1951"></ic-date-input><ic-buttontype="submit"value="Submit"></ic-button><ic-buttontype="reset"value="Reset"></ic-button></form>
With clearing value
The date input can be cleared by setting thevalue
attribute to one of the following:
-
empty string
-
null
-
undefined
Interactive example
<ic-date-inputid="date-input-clear-value"label="When would you like to collect your coffee?"date-format="DD/MM/YYYY"value="21/01/2001"></ic-date-input><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>