Skip to content

Date picker API

import { DatePicker } from '@cimpress-ui/react';

Date picker uses the @internationalized/date package to represent dates and times. You do not need to install this package separately. All exports from @internationalized/date are re-exported from @cimpress-ui/react/date.

Refer to @internationalized/date documentation to learn more about it. Remember that whenever the documentation instructs you to import something from @internationalized/date, you can import the same thing from @cimpress-ui/react/date instead.

To display a time within the date picker, pass a CalendarDateTime instance to the value or defaultValue prop. You can also control how many date/time segments are displayed using the granularity prop.

Provide a ZonedDateTime instance to the date picker to make it time zone aware.

This component can be used in a controlled or uncontrolled way.

In the controlled way, this component doesn’t maintain its own internal state, and its value is provided by the parent component. Use the controlled way when you need to be able to change the state of this component in other parts of your application.

In the uncontrolled way, this component maintains its own internal state, and can optionally notify the parent component when its internal state changes. Use the uncontrolled way when you don’t need to change the state of this component in other parts of your application.

This component exposes an imperative API through the apiRef prop. This API allows triggering behaviors that can’t be expressed by props.

Grids in the popup calendar follow the ARIA grid pattern. See the linked page for a list of available keyboard interactions.

Each date and time unit in the date picker field is an individually focusable and editable segment. Each segment can be edited using a keyboard, and incremented/decremented using up/down arrow keys. Use left/right arrow keys or the Tab key to move between segments.

DatePicker requires a textual label to remain accessible to assistive technologies. See our accessibility guide for more details.

By default, DatePicker selects a calendar system based on the application’s locale. You can force the date picker to use a specific calendar system using a locale extension subtag.

Date picker can integrate with native HTML forms. See our forms guide to learn how to work with forms.

Allows users to enter or select a date and time value.

See date picker usage guidelines.

Ref<HTMLDivElement>

The ref type for this component.

DatePickerProps<T extends DateValue>
string

The element's unique identifier. See MDN.

boolean

Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.

string

Sets the CSS className for the element. Only use as a last resort. Use style props instead.

See styling guide.

CSSProperties

Sets the CSS style for the element. Only use as a last resort. Use style props instead.

See styling guide.

string

The content to display as the label.

string

Defines a string value that labels the current element.

string

Identifies the element (or elements) that labels the current element.

string

Identifies the element (or elements) that describes the object.

string

Identifies the element (or elements) that provide a detailed, extended description for the object.

string

The <form> element to associate the input with. The value of this attribute must be the id of a <form> in the same document. See MDN.

string

The name of the input element, used when submitting an HTML form. See MDN.

string

A description for the field. Provides a hint such as specific requirements for what to choose.

FieldError

An error message for the field.

(value: MappedDateValue) => string | true | string[] | undefined

A function that returns an error message (or true) if a given value is invalid. Validation errors are displayed to the user when the form is submitted. For real-time validation, use the error prop instead.

RefObject<DatePickerApi | null>

A React ref that allows access to the imperative API of this component.

DateValue | null

Controls the currently focused date within the calendar.

DateValue | null

The date that is focused when the calendar first mounts (uncountrolled).

DateValue | null

The minimum allowed date that a user may select.

DateValue | null

The maximum allowed date that a user may select.

(date: DateValue) => boolean

Callback that is called for each date of the calendar. If it returns true, then the date is unavailable.

T | null

A placeholder date that influences the format of the placeholder shown when no value is selected. Defaults to today's date at midnight.

Granularity

Determines the smallest unit that is displayed in the date picker. By default, this is "day" for dates, and "minute" for times.

'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat'

The day that starts the week.

string

Describes the type of autocomplete functionality the input should provide if any. See MDN.

boolean

Whether the overlay is open by default (controlled).

boolean

Whether the overlay is open by default (uncontrolled).

(isOpen: boolean) => void

Handler that is called when the overlay's open state changes.

(e: FocusEvent<Element>) => void

Handler that is called when the element receives focus.

(e: FocusEvent<Element>) => void

Handler that is called when the element loses focus.

boolean

Whether the element should receive focus on render.

boolean

Whether user input is required on the input before form submission.

boolean

Whether the input value is invalid.

boolean

Whether the input is disabled.

boolean

Whether the input can be selected but not changed by the user.

T | null

The current value (controlled).

T | null

The default value (uncontrolled).

(value: MappedDateValue<T> | null) => void

Handler that is called when the value changes.

StyleProps
Responsive<Spacing | "auto">

The amount of margin applied to all edges of this component.

Responsive<Spacing | "auto">

The amount of margin applied to the left and right edges of this component. Takes priority over margin.

Responsive<Spacing | "auto">

The amount of margin applied to the top and bottom edges of this component. Takes priority over margin.

Responsive<Spacing | "auto">

The amount of margin applied to the top edge of this component. Takes priority over marginY and margin.

Responsive<Spacing | "auto">

The amount of margin applied to the right edge of this component. Takes priority over marginX and margin.

Responsive<Spacing | "auto">

The amount of margin applied to the bottom edge of this component. Takes priority over marginY and margin.

Responsive<Spacing | "auto">

The amount of margin applied to the left edge of this component. Takes priority over marginX and margin.