- Spec files
npm-react-aria
Describes: pkg:npm/react-aria@3.43.x
- Description
- Comprehensive library of unstyled React hooks providing accessible UI primitives with full WAI-ARIA compliance and internationalization support.
- Author
- tessl
- Last updated
date-time.md docs/
1# Date and Time23Date and time input components with comprehensive internationalization, accessibility, and validation support. All components handle various date formats, locales, time zones, and provide proper keyboard navigation.45## Capabilities67### Date Picker89Provides date picker behavior with calendar popup and text input.1011```typescript { .api }12/**13* Provides date picker behavior and accessibility14* @param props - Date picker configuration15* @param state - Date picker state management16* @param ref - Ref to the date picker element17* @returns Date picker props and state18*/19function useDatePicker(props: AriaDatePickerProps, state: DatePickerState, ref: RefObject<Element>): DatePickerAria;2021interface AriaDatePickerProps {22/** Current date value */23value?: DateValue | null;24/** Default date value (uncontrolled) */25defaultValue?: DateValue | null;26/** Handler called when date changes */27onChange?: (value: DateValue | null) => void;28/** Minimum allowed date */29minValue?: DateValue;30/** Maximum allowed date */31maxValue?: DateValue;32/** Whether the picker is disabled */33isDisabled?: boolean;34/** Whether the picker is read-only */35isReadOnly?: boolean;36/** Whether the picker is required */37isRequired?: boolean;38/** Validation state */39validationState?: 'valid' | 'invalid';40/** Auto-focus behavior */41autoFocus?: boolean;42/** Date formatting options */43granularity?: 'day' | 'hour' | 'minute' | 'second';44/** Hide the time zone */45hideTimeZone?: boolean;46/** Hour cycle preference */47hourCycle?: 12 | 24;48/** Whether to show era for certain calendars */49showEra?: boolean;50/** Placeholder date to use when value is null */51placeholderValue?: DateValue;52/** Whether dates are disabled */53isDateUnavailable?: (date: DateValue) => boolean;54}5556interface DatePickerAria {57/** Props for the date picker group element */58groupProps: DOMAttributes<Element>;59/** Props for the label element */60labelProps: DOMAttributes<Element>;61/** Props for the date field */62fieldProps: DOMAttributes<Element>;63/** Props for the calendar button */64buttonProps: ButtonHTMLAttributes<HTMLButtonElement>;65/** Props for the dialog element */66dialogProps: DOMAttributes<Element>;67/** Props for the calendar element */68calendarProps: DOMAttributes<Element>;69/** Props for the description element */70descriptionProps: DOMAttributes<Element>;71/** Props for the error message element */72errorMessageProps: DOMAttributes<Element>;73/** Whether the calendar is open */74isOpen: boolean;75/** Set the calendar open state */76setOpen: (isOpen: boolean) => void;77}78```7980### Date Range Picker8182Provides date range picker behavior for selecting start and end dates.8384```typescript { .api }85/**86* Provides date range picker behavior and accessibility87* @param props - Date range picker configuration88* @param state - Date range picker state89* @param ref - Ref to the date range picker element90* @returns Date range picker props and state91*/92function useDateRangePicker(props: AriaDateRangePickerProps, state: DateRangePickerState, ref: RefObject<Element>): DateRangePickerAria;9394interface AriaDateRangePickerProps {95/** Current date range value */96value?: DateRange | null;97/** Default date range value (uncontrolled) */98defaultValue?: DateRange | null;99/** Handler called when range changes */100onChange?: (value: DateRange | null) => void;101/** Minimum allowed date */102minValue?: DateValue;103/** Maximum allowed date */104maxValue?: DateValue;105/** Whether the picker is disabled */106isDisabled?: boolean;107/** Whether the picker is read-only */108isReadOnly?: boolean;109/** Whether the picker is required */110isRequired?: boolean;111/** Validation state */112validationState?: 'valid' | 'invalid';113/** Auto-focus behavior */114autoFocus?: boolean;115/** Whether dates are disabled */116isDateUnavailable?: (date: DateValue) => boolean;117/** Allow non-contiguous ranges */118allowsNonContiguousRanges?: boolean;119}120121interface DateRangePickerAria {122/** Props for the date range picker group element */123groupProps: DOMAttributes<Element>;124/** Props for the label element */125labelProps: DOMAttributes<Element>;126/** Props for the start field */127startFieldProps: DOMAttributes<Element>;128/** Props for the end field */129endFieldProps: DOMAttributes<Element>;130/** Props for the calendar button */131buttonProps: ButtonHTMLAttributes<HTMLButtonElement>;132/** Props for the dialog element */133dialogProps: DOMAttributes<Element>;134/** Props for the range calendar element */135calendarProps: DOMAttributes<Element>;136/** Props for the description element */137descriptionProps: DOMAttributes<Element>;138/** Props for the error message element */139errorMessageProps: DOMAttributes<Element>;140}141```142143### Date Field144145Provides date input field behavior with segment-based editing.146147```typescript { .api }148/**149* Provides date field behavior and accessibility150* @param props - Date field configuration151* @param state - Date field state152* @param ref - Ref to the date field element153* @returns Date field props and state154*/155function useDateField(props: AriaDateFieldProps, state: DateFieldState, ref: RefObject<Element>): DateFieldAria;156157/**158* Provides date segment behavior for individual date parts159* @param segment - Date segment information160* @param state - Date field state161* @param ref - Ref to the segment element162* @returns Date segment props and state163*/164function useDateSegment(segment: DateSegment, state: DateFieldState, ref: RefObject<Element>): DateSegmentAria;165166interface AriaDateFieldProps {167/** Current date value */168value?: DateValue | null;169/** Default date value (uncontrolled) */170defaultValue?: DateValue | null;171/** Handler called when date changes */172onChange?: (value: DateValue | null) => void;173/** Minimum allowed date */174minValue?: DateValue;175/** Maximum allowed date */176maxValue?: DateValue;177/** Whether the field is disabled */178isDisabled?: boolean;179/** Whether the field is read-only */180isReadOnly?: boolean;181/** Whether the field is required */182isRequired?: boolean;183/** Validation state */184validationState?: 'valid' | 'invalid';185/** Auto-focus behavior */186autoFocus?: boolean;187/** Date formatting options */188granularity?: 'day' | 'hour' | 'minute' | 'second';189/** Hide the time zone */190hideTimeZone?: boolean;191/** Hour cycle preference */192hourCycle?: 12 | 24;193/** Whether to show era */194showEra?: boolean;195/** Placeholder date to use when value is null */196placeholderValue?: DateValue;197/** Locale for formatting */198locale?: string;199/** Date formatting options */200formatOptions?: Intl.DateTimeFormatOptions;201}202203interface DateFieldAria {204/** Props for the label element */205labelProps: DOMAttributes<Element>;206/** Props for the field group element */207fieldProps: DOMAttributes<Element>;208/** Props for the description element */209descriptionProps: DOMAttributes<Element>;210/** Props for the error message element */211errorMessageProps: DOMAttributes<Element>;212}213214interface DateSegmentAria {215/** Props for the segment element */216segmentProps: DOMAttributes<Element>;217}218```219220### Time Field221222Provides time input field behavior with hour, minute, and second segments.223224```typescript { .api }225/**226* Provides time field behavior and accessibility227* @param props - Time field configuration228* @param state - Time field state229* @param ref - Ref to the time field element230* @returns Time field props and state231*/232function useTimeField(props: AriaTimeFieldProps, state: TimeFieldState, ref: RefObject<Element>): TimeFieldAria;233234interface AriaTimeFieldProps {235/** Current time value */236value?: TimeValue | null;237/** Default time value (uncontrolled) */238defaultValue?: TimeValue | null;239/** Handler called when time changes */240onChange?: (value: TimeValue | null) => void;241/** Minimum allowed time */242minValue?: TimeValue;243/** Maximum allowed time */244maxValue?: TimeValue;245/** Whether the field is disabled */246isDisabled?: boolean;247/** Whether the field is read-only */248isReadOnly?: boolean;249/** Whether the field is required */250isRequired?: boolean;251/** Validation state */252validationState?: 'valid' | 'invalid';253/** Auto-focus behavior */254autoFocus?: boolean;255/** Time granularity */256granularity?: 'hour' | 'minute' | 'second';257/** Hide the time zone */258hideTimeZone?: boolean;259/** Hour cycle preference */260hourCycle?: 12 | 24;261/** Placeholder time to use when value is null */262placeholderValue?: TimeValue;263}264265interface TimeFieldAria {266/** Props for the label element */267labelProps: DOMAttributes<Element>;268/** Props for the field group element */269fieldProps: DOMAttributes<Element>;270/** Props for the description element */271descriptionProps: DOMAttributes<Element>;272/** Props for the error message element */273errorMessageProps: DOMAttributes<Element>;274}275```276277### Calendar278279Provides calendar behavior for date selection with month navigation.280281```typescript { .api }282/**283* Provides calendar behavior and accessibility284* @param props - Calendar configuration285* @param state - Calendar state286* @param ref - Ref to the calendar element287* @returns Calendar props and state288*/289function useCalendar(props: AriaCalendarProps, state: CalendarState, ref: RefObject<Element>): CalendarAria;290291/**292* Provides calendar grid behavior for the days grid293* @param props - Calendar grid configuration294* @param state - Calendar state295* @param ref - Ref to the grid element296* @returns Calendar grid props297*/298function useCalendarGrid(props: AriaCalendarGridProps, state: CalendarState, ref: RefObject<Element>): CalendarGridAria;299300/**301* Provides calendar cell behavior for individual date cells302* @param props - Calendar cell configuration303* @param state - Calendar state304* @param ref - Ref to the cell element305* @returns Calendar cell props and state306*/307function useCalendarCell(props: AriaCalendarCellProps, state: CalendarState, ref: RefObject<Element>): CalendarCellAria;308309interface AriaCalendarProps extends CalendarProps {310/** Current selected date(s) */311value?: DateValue | DateRange | null;312/** Default selected date(s) (uncontrolled) */313defaultValue?: DateValue | DateRange | null;314/** Handler called when selection changes */315onChange?: (value: DateValue | DateRange | null) => void;316/** Currently focused date */317focusedValue?: DateValue;318/** Default focused date (uncontrolled) */319defaultFocusedValue?: DateValue;320/** Handler called when focus changes */321onFocusChange?: (value: DateValue) => void;322/** Minimum allowed date */323minValue?: DateValue;324/** Maximum allowed date */325maxValue?: DateValue;326/** Whether the calendar is disabled */327isDisabled?: boolean;328/** Whether the calendar is read-only */329isReadOnly?: boolean;330/** Auto-focus behavior */331autoFocus?: boolean;332/** Whether dates are unavailable */333isDateUnavailable?: (date: DateValue) => boolean;334/** Validation state */335validationState?: 'valid' | 'invalid';336/** Error message */337errorMessage?: ReactNode;338}339340interface CalendarAria {341/** Props for the calendar element */342calendarProps: DOMAttributes<Element>;343/** Props for the title element */344titleProps: DOMAttributes<Element>;345/** Props for the previous button */346prevButtonProps: ButtonHTMLAttributes<HTMLButtonElement>;347/** Props for the next button */348nextButtonProps: ButtonHTMLAttributes<HTMLButtonElement>;349/** Props for the error message element */350errorMessageProps: DOMAttributes<Element>;351}352```353354### Range Calendar355356Provides range calendar behavior for selecting date ranges.357358```typescript { .api }359/**360* Provides range calendar behavior and accessibility361* @param props - Range calendar configuration362* @param state - Range calendar state363* @param ref - Ref to the calendar element364* @returns Range calendar props and state365*/366function useRangeCalendar(props: AriaRangeCalendarProps, state: RangeCalendarState, ref: RefObject<Element>): CalendarAria;367368interface AriaRangeCalendarProps extends RangeCalendarProps {369/** Current selected range */370value?: DateRange | null;371/** Default selected range (uncontrolled) */372defaultValue?: DateRange | null;373/** Handler called when range changes */374onChange?: (value: DateRange | null) => void;375/** Currently focused date */376focusedValue?: DateValue;377/** Default focused date (uncontrolled) */378defaultFocusedValue?: DateValue;379/** Handler called when focus changes */380onFocusChange?: (value: DateValue) => void;381/** Minimum allowed date */382minValue?: DateValue;383/** Maximum allowed date */384maxValue?: DateValue;385/** Whether the calendar is disabled */386isDisabled?: boolean;387/** Whether the calendar is read-only */388isReadOnly?: boolean;389/** Auto-focus behavior */390autoFocus?: boolean;391/** Whether dates are unavailable */392isDateUnavailable?: (date: DateValue) => boolean;393/** Allow non-contiguous ranges */394allowsNonContiguousRanges?: boolean;395/** Validation state */396validationState?: 'valid' | 'invalid';397}398```399400## Types401402```typescript { .api }403interface DateValue {404/** Calendar system */405calendar: Calendar;406/** Era */407era?: string;408/** Year */409year: number;410/** Month (1-based) */411month: number;412/** Day */413day: number;414/** Convert to native Date object */415toDate(timeZone: string): Date;416/** Get formatted string */417toString(): string;418/** Compare to another date */419compare(other: DateValue): number;420}421422interface TimeValue {423/** Hour (24-hour format) */424hour: number;425/** Minute */426minute: number;427/** Second */428second?: number;429/** Millisecond */430millisecond?: number;431/** Convert to string */432toString(): string;433/** Compare to another time */434compare(other: TimeValue): number;435}436437interface DateRange {438/** Start date */439start: DateValue;440/** End date */441end: DateValue;442}443444interface DateSegment {445/** Type of segment */446type: 'literal' | 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | 'dayPeriod' | 'era' | 'timeZoneName';447/** Display text */448text: string;449/** Current value */450value?: number;451/** Minimum value */452minValue?: number;453/** Maximum value */454maxValue?: number;455/** Whether segment is placeholder */456isPlaceholder: boolean;457/** Whether segment is editable */458isEditable: boolean;459}460461interface DateFieldState {462/** Current date value */463value: DateValue | null;464/** Set the date value */465setValue(value: DateValue | null): void;466/** Date segments */467segments: DateSegment[];468/** Currently focused segment */469focusedSegment: number | null;470/** Set the focused segment */471setFocusedSegment(index: number | null): void;472/** Increment a segment */473increment(index: number): void;474/** Decrement a segment */475decrement(index: number): void;476/** Set segment value */477setSegment(index: number, value: number): void;478/** Clear the value */479clearSegment(index: number): void;480/** Whether the field is invalid */481isInvalid: boolean;482/** Validation state */483validationState: 'valid' | 'invalid';484}485486interface CalendarState {487/** Current date value */488value: DateValue | DateRange | null;489/** Set the date value */490setValue(value: DateValue | DateRange | null): void;491/** Currently focused date */492focusedDate: DateValue;493/** Set the focused date */494setFocusedDate(date: DateValue): void;495/** Navigate to previous month */496focusPreviousPage(): void;497/** Navigate to next month */498focusNextPage(): void;499/** Navigate to previous year */500focusPreviousYear(): void;501/** Navigate to next year */502focusNextYear(): void;503/** Select a date */504selectDate(date: DateValue): void;505/** Whether a date is selected */506isSelected(date: DateValue): boolean;507/** Whether a date is focused */508isFocused(date: DateValue): boolean;509/** Whether a date is disabled */510isDisabled(date: DateValue): boolean;511/** Whether a date is unavailable */512isUnavailable(date: DateValue): boolean;513}514```