Skip to main content

Component | Date Input

Render a date input box.

ui.dateInput("date-input-key", { 
label: "Enter your birthday",
onEnter: (value) => console.log(value)
})

Learn more about working with inputs.

API reference

Function signature

/**
* One of the following:
* - A JS Date object in UTC
* - A human readable object with year, month (1-12), and day (1-31)
* - `null` to ignore the parameter and use the default value
*/
type DateInput =
| {
year: number;
month: number; // 1-12
day: number; // 1-31
}
| Date // Assumes UTC for the given date
| null

/**
* An object with human readable values for year, month (1-12), and day (1-31)
* and a JS Date object in UTC for the selected date.
*/
type DateOutput =
| {
year: number;
month: number; // 1-12
day: number; // 1-31
jsDate: Date; // UTC midnight of the selected date
}
| null // Passes `null` if no date was selected

ui.dateInput(
id: string,
properties: Partial<{
label: string,
description: string,
required: boolean,
min: DateInput,
max: DateInput,
initialValue: DateInput,
validate: (value: DateOutput | null) => string | void,
onEnter: (value: DateOutput | null) => void,
style: Style | null
}>
)

Parameters

id

required string
A unique identifier for the component. This is necessary so that Compose can properly pass user actions back to the component.

properties.label

optional string

The label to display above the date input. If not provided, the label will be inferred from the id.


properties.description

optional string

A description to display between the label and date input box.


properties.required

optional boolean

Validate that the date input is not empty before submitting the form it's part of or calling it's onEnter hook. Defaults to true.


properties.min Optional DateInput | null

The earliest date that can be selected. If not provided, there is no minimum date.

The parameter expects either a JS Date in UTC or a human readable object with year, month (1-12), and day (1-31).

type DateInput = 
| {
year: number;
month: number; // 1-12
day: number; // 1-31
}
| Date // Assumes UTC for the given date
| null // Use default value (i.e. no minimum date)

properties.max Optional DateInput | null

The latest date that can be selected. If not provided, there is no maximum date.

The parameter expects either a JS Date in UTC or a human readable object with year, month (1-12), and day (1-31).

type DateInput = 
| {
year: number;
month: number; // 1-12
day: number; // 1-31
}
| Date // Assumes UTC for the given date
| null // Use default value (i.e. no maximum date)

properties.initialValue Optional DateInput | null

The initial value to set for the date input. If not provided, the date input will be empty initially.

The parameter expects either a JS Date in UTC or a human readable object with year, month (1-12), and day (1-31).

type DateInput = 
| {
year: number;
month: number; // 1-12
day: number; // 1-31
}
| Date // Assumes UTC for the given date
| null // Use default value (i.e. no initial value)

properties.validate Optional (value: DateOutput) => string | void

Supply a custom function to validate the date input.

The validator will be passed an object with the following properties:

type DateOutput = 
| {
year: number;
month: number; // 1-12
day: number; // 1-31
jsDate: Date; // UTC midnight of the selected date
}
| null // Passes `null` if no date was selected

properties.onEnter Optional (value: DateOutput) => void

Supply a callback function that is called when the user presses enter while the date input is focused.

The callback will be passed an object with the following properties:

type DateOutput = 
| {
year: number;
month: number; // 1-12
day: number; // 1-31
jsDate: Date; // UTC midnight of the selected date
}
| null // Passes `null` if no date was selected

properties.style

optional Style

Directly style the underlying element using CSS. See the styling guide for more details on available style properties.