Skip to content

Date input

...

Attention!

The localization format of the input comes from the format settings of the client's operation system.

Browser support

...

Parameters

The CSS component uses the <label> tag.

The parametrization of the component can be done with the following custom HTML params:

NameTypeDescription
z-date-inputstring

The main parameter has two components following the pattern: <shape><?:size>.

  • shape: Establishes the styling of the input. Default value is line . Possible values are: shaped or line. ,
  • size: (optional) defines de size of the input. The default value is m, being omitted from the param. The possible values are: m or l. Check the sizes section.
labelstringLabel of the input
readonlyboolean?Transforms the input into an output
valuestring?Value of the model
disabledboolean?Blocks the interaction with the input component.
requiredboolean?Marks the input component as required.
namestring?Identification for the field inside the form
help-textstring?The forced message to be shown under the input
typestring

Type of input. Possible values are:

  • date: it will a date, without the day of the month as yyyy-mm-dd.
  • month: it will handle a shorter version of the date, without the day of the month as yyyy-mm.
  • datetime-localit will handle an extended version of the date including the time as yyyy-mm-ddThh:mm following the ISO string format.
  • week: it will provide the year and the week number based on ISO 8601, where the format will be yyyy-Wnn

The events emitted from the component are:

NamePayloadDescription
onchangestringReturns the new value of the "value" attribute

Invalid input

If you require to make the input invalid, use the native API of the input using setCustomValidity. If no message is provided, the input is set to valid.

ts
// Make invalid
input.setCustomValidity('Error message');
input.checkValidity();

Or you can use the data-invalid attribute if you are using the scripts:

html
<label z-date-input>
  <span>Date input</span>
  <input type="date" data-invalid />
</label>

Playground

Customization

HTML Examples

Imports
html
<script type="module" src="/0.3.6/@zurich/css-components/javascript.js"></script>
<link rel="stylesheet" href="/0.3.6/@zurich/css-components/base.css" />
<link rel="stylesheet" href="/0.3.6/@zurich/css-components/DateInput.css" />
Code
html
<!-- Default -->
  <label z-date-input>
    <span>Date input</span>
    <input type="date" />
  </label>
  <label z-date-input="shaped">
    <span>Date input</span>
    <input type="date" />
  </label>

<!-- With value -->
  <label z-date-input>
    <span>Date input</span>
    <input type="date" value="2024-09-21" />
  </label>
  <label z-date-input="shaped">
    <span>Date input</span>
    <input type="date" value="2024-09-21" />
  </label>

<!-- Datetime-local -->
  <label z-date-input>
    <span>Date input</span>
    <input type="datetime-local" />
  </label>
  <label z-date-input="shaped">
    <span>Date input</span>
    <input type="datetime-local" />
  </label>

<!-- Month -->
  <label z-date-input>
    <span>Date input</span>
    <input type="month" />
  </label>
  <label z-date-input="shaped">
    <span>Date input</span>
    <input type="month" />
  </label>

<!-- Week -->
  <label z-date-input>
    <span>Date input</span>
    <input type="week" />
  </label>
  <label z-date-input="shaped">
    <span>Date input</span>
    <input type="week" />
  </label>

<!-- Disabled -->
  <label z-date-input>
    <span>Date input</span>
    <input type="date" disabled />
  </label>
  <label z-date-input="shaped">
    <span>Date input</span>
    <input type="date" disabled />
  </label>

<!-- Readonly -->
  <label z-date-input>
    <span>Date input</span>
    <input type="date" readonly value="2024-09-21" />
  </label>
  <label z-date-input="shaped">
    <span>Date input</span>
    <input type="date" readonly value="2024-09-21" />
  </label>

<!-- With help text -->
  <label z-date-input>
    <span>Date input</span>
    <small>Help text</small>
    <input type="date" />
  </label>
  <label z-date-input="shaped">
    <span>Date input</span>
    <small>Help text</small>
    <input type="date" />
  </label>

<!-- Invalid -->

  <label z-date-input>
    <span>Date input</span>
    <small>Invalid input</small>
    <input type="date" data-invalid />
  </label>
  <label z-date-input="shaped">
    <span>Date input</span>
    <small>Invalid input</small>
    <input type="date" data-invalid />
  </label>