useDatePicker

Provides the behavior and accessibility implementation for a date picker component. A date picker combines a DateField and a Calendar popover to allow users to enter or select a date and time value.

Event date
Example
DatePicker.tsx
DatePicker.css
DateField.css
Calendar.css
Button.css
Form.css
Popover.css
import {DatePicker} from './DatePicker';

<DatePicker label="Event date" />

API

Event date9 / 17 / 2021GroupLabelButtonFieldSeptember 2021SMTWTF5789101314151619202122232412326272930628S11182541217CalendarPopover
<DatePicker>
  <Label />
  <Group>
    <DateInput>
      {segment => <DateSegment segment={segment} />}
    </DateInput>
    <Button />
  </Group>
  <Popover>
    <Calendar />
  </Popover>
</DatePicker>
useDatePickerState<T extends = >(props: <T>): useDatePicker<T extends >( props: <T>, state: , ref: <Elementnull> ):

DatePickerState

Properties

NameType
dateValuenull

The date portion of the value. This may be set prior to value if the user has selected a date but has not yet selected a time.

timeValuenull

The time portion of the value. This may be set prior to value if the user has selected a time but has not yet selected a date.

granularity

The granularity for the field, based on the granularity prop and current value.

hasTimeboolean

Whether the date picker supports selecting a time, according to the granularity prop and current value.

pointnull

The cursor position when the overlay was triggered, relative to the window viewport.

realtimeValidation

Realtime validation results, updated as the user edits the value.

displayValidation

Currently displayed validation results, updated when the user commits their changes.

valuenull

The currently selected date.

defaultValuenull

The default date.

Methods

setValue(value: null): void
Sets the selected date.
setDateValue(value: ): void
Sets the date portion of the value.
setTimeValue(value: ): void
Sets the time portion of the value.
setOpen(isOpen: boolean): void
Sets whether the calendar popover is open.
formatValue(locale: string, fieldOptions: ): string
Formats the selected value using the given options.
getDateFormatter(locale: string, formatOptions: ):
Gets a formatter based on state's props.
open(): void
Opens the overlay.
close(): void
Closes the overlay.
toggle(): void
Toggles the overlay's visibility.
setPoint(point: ): void
Sets the cursor position relative to the window viewport.
updateValidation(result: ): void
Updates the current validation result. Not displayed to the user until commitValidation is called.
resetValidation(): void
Resets the displayed validation state to valid when the user resets the form.
commitValidation(): void
Commits the realtime validation so it is displayed to the user.

AriaDatePickerProps

NameTypeDefault
pageBehaviorDefault: visible

Controls the behavior of paging. Pagination either works by advancing the visible page by visibleDuration (default) or one unit of visibleDuration.

firstDayOfWeek'sun''mon''tue''wed''thu''fri''sat'Default:

The day that starts the week.

isDateUnavailable(date: ) => booleanDefault:

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

placeholderValuenullDefault:

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

hourCycle1224Default:

Whether to display the time in 12 or 24 hour format. By default, this is determined by the user's locale.

granularityDefault:

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

hideTimeZonebooleanDefault: false

Whether to hide the time zone abbreviation.

shouldForceLeadingZerosbooleanDefault:

Whether to always show leading zeros in the month, day, and hour fields. By default, this is determined by the user's locale.

isDisabledbooleanDefault:

Whether the input is disabled.

isReadOnlybooleanDefault:

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

valuenullDefault:

The current value (controlled).

defaultValuenullDefault:

The default value (uncontrolled).

onChange(value: <>null) => voidDefault:

Handler that is called when the value changes.

DatePickerAria

NameType
labelPropsDOMAttributes

Props for the date picker's visible label element, if any.

groupProps

Props for the grouping element containing the date field and button.

fieldProps<>

Props for the date field.

buttonProps

Props for the popover trigger button.

descriptionPropsDOMAttributes

Props for the description element, if any.

errorMessagePropsDOMAttributes

Props for the error message element, if any.

dialogProps

Props for the popover dialog.

calendarProps<>

Props for the calendar within the popover dialog.

validationDetailsValidityState

The native validation details for the input.