1
1
import { useDatePicker , useDateRangePicker } from "@react-aria/datepicker" ;
2
2
import { useDatePickerState , useDateRangePickerState } from "@react-stately/datepicker" ;
3
- import { useRef } from "react" ;
3
+ import { HTMLAttributes , useRef } from "react" ;
4
4
import { match } from "ts-pattern" ;
5
5
import { FieldProps } from "../Field/FieldProps" ;
6
6
import { CalendarDate , DateValue , getLocalTimeZone } from "@internationalized/date" ;
7
7
import { BaseDateInput } from "./BaseDateInput" ;
8
8
import { RangeValue } from "@react-types/shared" ;
9
9
import { DateProps , SingleDateProps , RangeDateProps } from "./types" ;
10
10
import { dateToCalendarDate } from "./utils" ;
11
+ import { AtLeast } from "src/util/AtLeast" ;
11
12
12
13
type StandaloneProps < T > = Pick <
13
14
FieldProps < T > ,
@@ -16,11 +17,15 @@ type StandaloneProps<T> = Pick<
16
17
17
18
type SingleDateInputProps = SingleDateProps &
18
19
StandaloneProps < Date | null > &
19
- DateProps & { validationState : "valid" | "invalid" } ;
20
+ DateProps & { validationState ?: "valid" | "invalid" } & AtLeast <
21
+ Pick < HTMLAttributes < HTMLInputElement > , "aria-label" | "aria-labelledby" >
22
+ > ;
20
23
21
24
type RangeDateInputProps = RangeDateProps &
22
25
StandaloneProps < [ Date , Date ] | null > &
23
- DateProps & { validationState : "valid" | "invalid" } ;
26
+ DateProps & { validationState ?: "valid" | "invalid" } & AtLeast <
27
+ Pick < HTMLAttributes < HTMLInputElement > , "aria-label" | "aria-labelledby" >
28
+ > ;
24
29
25
30
function SingleDateInput ( props : SingleDateInputProps ) {
26
31
const localTimeZone = getLocalTimeZone ( ) ;
@@ -34,7 +39,7 @@ function SingleDateInput(props: SingleDateInputProps) {
34
39
} ,
35
40
isDisabled : props . disabled ,
36
41
isReadOnly : props . isReadOnly ?? props . readOnly ,
37
- validationState : props . validationState ,
42
+ validationState : props . validationState ?? "valid" ,
38
43
minValue : props . minDate ? dateToCalendarDate ( props . minDate ) : undefined ,
39
44
maxValue : props . maxDate ? dateToCalendarDate ( props . maxDate ) : undefined ,
40
45
isDateUnavailable : props . shouldDisableDate
@@ -82,7 +87,7 @@ function RangeDateInput(props: RangeDateInputProps) {
82
87
} ,
83
88
isDisabled : props . disabled ,
84
89
isReadOnly : props . isReadOnly ?? props . readOnly ,
85
- validationState : props . validationState ,
90
+ validationState : props . validationState ?? "valid" ,
86
91
minValue : props . minDate ? dateToCalendarDate ( props . minDate ) : undefined ,
87
92
maxValue : props . maxDate ? dateToCalendarDate ( props . maxDate ) : undefined ,
88
93
isDateUnavailable : props . shouldDisableDate
@@ -112,8 +117,11 @@ function RangeDateInput(props: RangeDateInputProps) {
112
117
export type DateInputProps = SingleDateInputProps | RangeDateInputProps ;
113
118
114
119
export function DateInput ( props : SingleDateInputProps | RangeDateInputProps ) {
120
+ if ( props . type == undefined ) {
121
+ return < SingleDateInput { ...props } /> ;
122
+ }
115
123
return match ( props )
116
- . with ( { type : "single" } , { type : undefined } , ( props ) => < SingleDateInput { ...props } /> )
124
+ . with ( { type : "single" } , ( props ) => < SingleDateInput { ...props } /> )
117
125
. with ( { type : "range" } , ( props ) => < RangeDateInput { ...props } /> )
118
126
. exhaustive ( ) ;
119
127
}
0 commit comments