@react-aria/datepicker 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +728 -47
- package/dist/main.js.map +1 -1
- package/dist/module.js +729 -48
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +20 -18
- package/dist/types.d.ts.map +1 -1
- package/package.json +16 -16
- package/src/index.ts +1 -0
- package/src/useDateField.ts +12 -11
- package/src/useDatePicker.ts +11 -10
- package/src/useDatePickerGroup.ts +9 -7
- package/src/useDateRangePicker.ts +13 -12
- package/src/useDateSegment.ts +3 -2
- package/src/useDisplayNames.ts +3 -3
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AriaDatePickerProps, AriaTimeFieldProps, DateValue, TimeValue, AriaDateRangePickerProps } from "@react-types/datepicker";
|
|
2
2
|
import { DateFieldState, DatePickerState, DateSegment, DateRangePickerState } from "@react-stately/datepicker";
|
|
3
|
-
import {
|
|
3
|
+
import { DOMAttributes } from "@react-types/shared";
|
|
4
|
+
import { RefObject } from "react";
|
|
4
5
|
import { AriaButtonProps } from "@react-types/button";
|
|
5
6
|
import { AriaDialogProps } from "@react-types/dialog";
|
|
6
7
|
import { CalendarProps, RangeCalendarProps } from "@react-types/calendar";
|
|
@@ -8,39 +9,39 @@ export interface AriaDateFieldProps<T extends DateValue> extends Omit<AriaDatePi
|
|
|
8
9
|
}
|
|
9
10
|
export interface DateFieldAria {
|
|
10
11
|
/** Props for the field's visible label element, if any. */
|
|
11
|
-
labelProps:
|
|
12
|
+
labelProps: DOMAttributes;
|
|
12
13
|
/** Props for the field grouping element. */
|
|
13
|
-
fieldProps:
|
|
14
|
+
fieldProps: DOMAttributes;
|
|
14
15
|
/** Props for the description element, if any. */
|
|
15
|
-
descriptionProps:
|
|
16
|
+
descriptionProps: DOMAttributes;
|
|
16
17
|
/** Props for the error message element, if any. */
|
|
17
|
-
errorMessageProps:
|
|
18
|
+
errorMessageProps: DOMAttributes;
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
20
21
|
* Provides the behavior and accessibility implementation for a date field component.
|
|
21
22
|
* A date field allows users to enter and edit date and time values using a keyboard.
|
|
22
23
|
* Each part of a date value is displayed in an individually editable segment.
|
|
23
24
|
*/
|
|
24
|
-
export function useDateField<T extends DateValue>(props: AriaDateFieldProps<T>, state: DateFieldState, ref: RefObject<
|
|
25
|
+
export function useDateField<T extends DateValue>(props: AriaDateFieldProps<T>, state: DateFieldState, ref: RefObject<Element>): DateFieldAria;
|
|
25
26
|
/**
|
|
26
27
|
* Provides the behavior and accessibility implementation for a time field component.
|
|
27
28
|
* A time field allows users to enter and edit time values using a keyboard.
|
|
28
29
|
* Each part of a time value is displayed in an individually editable segment.
|
|
29
30
|
*/
|
|
30
|
-
export function useTimeField<T extends TimeValue>(props: AriaTimeFieldProps<T>, state: DateFieldState, ref: RefObject<
|
|
31
|
+
export function useTimeField<T extends TimeValue>(props: AriaTimeFieldProps<T>, state: DateFieldState, ref: RefObject<Element>): DateFieldAria;
|
|
31
32
|
export interface DatePickerAria {
|
|
32
33
|
/** Props for the date picker's visible label element, if any. */
|
|
33
|
-
labelProps:
|
|
34
|
+
labelProps: DOMAttributes;
|
|
34
35
|
/** Props for the grouping element containing the date field and button. */
|
|
35
|
-
groupProps:
|
|
36
|
+
groupProps: DOMAttributes;
|
|
36
37
|
/** Props for the date field. */
|
|
37
38
|
fieldProps: AriaDatePickerProps<DateValue>;
|
|
38
39
|
/** Props for the popover trigger button. */
|
|
39
40
|
buttonProps: AriaButtonProps;
|
|
40
41
|
/** Props for the description element, if any. */
|
|
41
|
-
descriptionProps:
|
|
42
|
+
descriptionProps: DOMAttributes;
|
|
42
43
|
/** Props for the error message element, if any. */
|
|
43
|
-
errorMessageProps:
|
|
44
|
+
errorMessageProps: DOMAttributes;
|
|
44
45
|
/** Props for the popover dialog. */
|
|
45
46
|
dialogProps: AriaDialogProps;
|
|
46
47
|
/** Props for the calendar within the popover dialog. */
|
|
@@ -50,7 +51,7 @@ export interface DatePickerAria {
|
|
|
50
51
|
* Provides the behavior and accessibility implementation for a date picker component.
|
|
51
52
|
* A date picker combines a DateField and a Calendar popover to allow users to enter or select a date and time value.
|
|
52
53
|
*/
|
|
53
|
-
export function useDatePicker<T extends DateValue>(props: AriaDatePickerProps<T>, state: DatePickerState, ref: RefObject<
|
|
54
|
+
export function useDatePicker<T extends DateValue>(props: AriaDatePickerProps<T>, state: DatePickerState, ref: RefObject<Element>): DatePickerAria;
|
|
54
55
|
type Field = 'era' | 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | 'dayPeriod' | 'timeZoneName' | 'weekday';
|
|
55
56
|
interface DisplayNames {
|
|
56
57
|
of(field: Field): string;
|
|
@@ -59,7 +60,7 @@ interface DisplayNames {
|
|
|
59
60
|
export function useDisplayNames(): DisplayNames;
|
|
60
61
|
export interface DateSegmentAria {
|
|
61
62
|
/** Props for the segment element. */
|
|
62
|
-
segmentProps:
|
|
63
|
+
segmentProps: DOMAttributes;
|
|
63
64
|
}
|
|
64
65
|
/**
|
|
65
66
|
* Provides the behavior and accessibility implementation for a segment in a date field.
|
|
@@ -69,9 +70,9 @@ export interface DateSegmentAria {
|
|
|
69
70
|
export function useDateSegment(segment: DateSegment, state: DateFieldState, ref: RefObject<HTMLElement>): DateSegmentAria;
|
|
70
71
|
export interface DateRangePickerAria {
|
|
71
72
|
/** Props for the date range picker's visible label element, if any. */
|
|
72
|
-
labelProps:
|
|
73
|
+
labelProps: DOMAttributes;
|
|
73
74
|
/** Props for the grouping element containing the date fields and button. */
|
|
74
|
-
groupProps:
|
|
75
|
+
groupProps: DOMAttributes;
|
|
75
76
|
/** Props for the start date field. */
|
|
76
77
|
startFieldProps: AriaDatePickerProps<DateValue>;
|
|
77
78
|
/** Props for the end date field. */
|
|
@@ -79,9 +80,9 @@ export interface DateRangePickerAria {
|
|
|
79
80
|
/** Props for the popover trigger button. */
|
|
80
81
|
buttonProps: AriaButtonProps;
|
|
81
82
|
/** Props for the description element, if any. */
|
|
82
|
-
descriptionProps:
|
|
83
|
+
descriptionProps: DOMAttributes;
|
|
83
84
|
/** Props for the error message element, if any. */
|
|
84
|
-
errorMessageProps:
|
|
85
|
+
errorMessageProps: DOMAttributes;
|
|
85
86
|
/** Props for the popover dialog. */
|
|
86
87
|
dialogProps: AriaDialogProps;
|
|
87
88
|
/** Props for the range calendar within the popover dialog. */
|
|
@@ -92,7 +93,8 @@ export interface DateRangePickerAria {
|
|
|
92
93
|
* A date range picker combines two DateFields and a RangeCalendar popover to allow
|
|
93
94
|
* users to enter or select a date and time range.
|
|
94
95
|
*/
|
|
95
|
-
export function useDateRangePicker<T extends DateValue>(props: AriaDateRangePickerProps<T>, state: DateRangePickerState, ref: RefObject<
|
|
96
|
+
export function useDateRangePicker<T extends DateValue>(props: AriaDateRangePickerProps<T>, state: DateRangePickerState, ref: RefObject<Element>): DateRangePickerAria;
|
|
96
97
|
export type { AriaDatePickerProps, AriaDateRangePickerProps } from '@react-types/datepicker';
|
|
98
|
+
export type { AriaTimeFieldProps } from '@react-types/datepicker';
|
|
97
99
|
|
|
98
100
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":"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","sources":["packages/@react-aria/datepicker/src/packages/@react-aria/datepicker/src/useDatePickerGroup.ts","packages/@react-aria/datepicker/src/packages/@react-aria/datepicker/src/useDateField.ts","packages/@react-aria/datepicker/src/packages/@react-aria/datepicker/src/useDatePicker.ts","packages/@react-aria/datepicker/src/packages/@react-aria/datepicker/src/useDisplayNames.ts","packages/@react-aria/datepicker/src/packages/@react-aria/datepicker/src/useDateSegment.ts","packages/@react-aria/datepicker/src/packages/@react-aria/datepicker/src/useDateRangePicker.ts","packages/@react-aria/datepicker/src/packages/@react-aria/datepicker/src/index.ts","packages/@react-aria/datepicker/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useDatePicker} from './useDatePicker';\nexport {useDateSegment} from './useDateSegment';\nexport {useDateField, useTimeField} from './useDateField';\nexport {useDateRangePicker} from './useDateRangePicker';\nexport {useDisplayNames} from './useDisplayNames';\n\nexport type {AriaDatePickerProps, AriaDateRangePickerProps} from '@react-types/datepicker';\nexport type {AriaDateFieldProps, DateFieldAria} from './useDateField';\nexport type {DatePickerAria} from './useDatePicker';\nexport type {DateRangePickerAria} from './useDateRangePicker';\nexport type {DateSegmentAria} from './useDateSegment';\nexport type {AriaTimeFieldProps} from '@react-types/datepicker';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/datepicker",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,21 +18,21 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@internationalized/date": "^3.0.
|
|
22
|
-
"@internationalized/message": "^3.0.8",
|
|
21
|
+
"@internationalized/date": "^3.0.1",
|
|
23
22
|
"@internationalized/number": "^3.1.1",
|
|
24
|
-
"@
|
|
25
|
-
"@react-aria/
|
|
26
|
-
"@react-aria/
|
|
27
|
-
"@react-aria/
|
|
28
|
-
"@react-aria/
|
|
29
|
-
"@react-aria/
|
|
30
|
-
"@react-
|
|
31
|
-
"@react-
|
|
32
|
-
"@react-types/
|
|
33
|
-
"@react-types/
|
|
34
|
-
"@react-types/
|
|
35
|
-
"@react-types/
|
|
23
|
+
"@internationalized/string": "^3.0.0",
|
|
24
|
+
"@react-aria/focus": "^3.7.0",
|
|
25
|
+
"@react-aria/i18n": "^3.5.0",
|
|
26
|
+
"@react-aria/interactions": "^3.10.0",
|
|
27
|
+
"@react-aria/label": "^3.4.0",
|
|
28
|
+
"@react-aria/spinbutton": "^3.1.2",
|
|
29
|
+
"@react-aria/utils": "^3.13.2",
|
|
30
|
+
"@react-stately/datepicker": "^3.0.1",
|
|
31
|
+
"@react-types/button": "^3.6.0",
|
|
32
|
+
"@react-types/calendar": "^3.0.1",
|
|
33
|
+
"@react-types/datepicker": "^3.1.0",
|
|
34
|
+
"@react-types/dialog": "^3.4.2",
|
|
35
|
+
"@react-types/shared": "^3.14.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "cd7c0ec917122c7612f653c22f8ed558f8b66ecd"
|
|
45
45
|
}
|
package/src/index.ts
CHANGED
|
@@ -21,3 +21,4 @@ export type {AriaDateFieldProps, DateFieldAria} from './useDateField';
|
|
|
21
21
|
export type {DatePickerAria} from './useDatePicker';
|
|
22
22
|
export type {DateRangePickerAria} from './useDateRangePicker';
|
|
23
23
|
export type {DateSegmentAria} from './useDateSegment';
|
|
24
|
+
export type {AriaTimeFieldProps} from '@react-types/datepicker';
|
package/src/useDateField.ts
CHANGED
|
@@ -13,27 +13,28 @@
|
|
|
13
13
|
import {AriaDatePickerProps, AriaTimeFieldProps, DateValue, TimeValue} from '@react-types/datepicker';
|
|
14
14
|
import {createFocusManager, FocusManager} from '@react-aria/focus';
|
|
15
15
|
import {DateFieldState} from '@react-stately/datepicker';
|
|
16
|
+
import {DOMAttributes} from '@react-types/shared';
|
|
16
17
|
import {filterDOMProps, mergeProps, useDescription} from '@react-aria/utils';
|
|
17
|
-
import {HTMLAttributes, RefObject, useEffect, useMemo, useRef} from 'react';
|
|
18
18
|
// @ts-ignore
|
|
19
19
|
import intlMessages from '../intl/*.json';
|
|
20
|
+
import {RefObject, useEffect, useMemo, useRef} from 'react';
|
|
20
21
|
import {useDatePickerGroup} from './useDatePickerGroup';
|
|
21
22
|
import {useField} from '@react-aria/label';
|
|
22
23
|
import {useFocusWithin} from '@react-aria/interactions';
|
|
23
|
-
import {
|
|
24
|
+
import {useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
24
25
|
|
|
25
26
|
// Allows this hook to also be used with TimeField
|
|
26
27
|
export interface AriaDateFieldProps<T extends DateValue> extends Omit<AriaDatePickerProps<T>, 'value' | 'defaultValue' | 'onChange' | 'minValue' | 'maxValue' | 'placeholderValue'> {}
|
|
27
28
|
|
|
28
29
|
export interface DateFieldAria {
|
|
29
30
|
/** Props for the field's visible label element, if any. */
|
|
30
|
-
labelProps:
|
|
31
|
+
labelProps: DOMAttributes,
|
|
31
32
|
/** Props for the field grouping element. */
|
|
32
|
-
fieldProps:
|
|
33
|
+
fieldProps: DOMAttributes,
|
|
33
34
|
/** Props for the description element, if any. */
|
|
34
|
-
descriptionProps:
|
|
35
|
+
descriptionProps: DOMAttributes,
|
|
35
36
|
/** Props for the error message element, if any. */
|
|
36
|
-
errorMessageProps:
|
|
37
|
+
errorMessageProps: DOMAttributes
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
// Data that is passed between useDateField and useDateSegment.
|
|
@@ -56,7 +57,7 @@ export const focusManagerSymbol = '__focusManager_' + Date.now();
|
|
|
56
57
|
* A date field allows users to enter and edit date and time values using a keyboard.
|
|
57
58
|
* Each part of a date value is displayed in an individually editable segment.
|
|
58
59
|
*/
|
|
59
|
-
export function useDateField<T extends DateValue>(props: AriaDateFieldProps<T>, state: DateFieldState, ref: RefObject<
|
|
60
|
+
export function useDateField<T extends DateValue>(props: AriaDateFieldProps<T>, state: DateFieldState, ref: RefObject<Element>): DateFieldAria {
|
|
60
61
|
let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({
|
|
61
62
|
...props,
|
|
62
63
|
labelElementType: 'span'
|
|
@@ -68,10 +69,10 @@ export function useDateField<T extends DateValue>(props: AriaDateFieldProps<T>,
|
|
|
68
69
|
}
|
|
69
70
|
});
|
|
70
71
|
|
|
71
|
-
let
|
|
72
|
+
let stringFormatter = useLocalizedStringFormatter(intlMessages);
|
|
72
73
|
let message = state.maxGranularity === 'hour' ? 'selectedTimeDescription' : 'selectedDateDescription';
|
|
73
74
|
let field = state.maxGranularity === 'hour' ? 'time' : 'date';
|
|
74
|
-
let description = state.value ?
|
|
75
|
+
let description = state.value ? stringFormatter.format(message, {[field]: state.formatValue({month: 'long'})}) : '';
|
|
75
76
|
let descProps = useDescription(description);
|
|
76
77
|
|
|
77
78
|
// If within a date picker or date range picker, the date field will have role="presentation" and an aria-describedby
|
|
@@ -97,7 +98,7 @@ export function useDateField<T extends DateValue>(props: AriaDateFieldProps<T>,
|
|
|
97
98
|
// rather than role="group". Since the date picker/date range picker already has a role="group"
|
|
98
99
|
// with a label and description, and the segments are already labeled by this as well, this
|
|
99
100
|
// avoids very verbose duplicate announcements.
|
|
100
|
-
let fieldDOMProps:
|
|
101
|
+
let fieldDOMProps: DOMAttributes;
|
|
101
102
|
if (props[roleSymbol] === 'presentation') {
|
|
102
103
|
fieldDOMProps = {
|
|
103
104
|
role: 'presentation'
|
|
@@ -136,6 +137,6 @@ export function useDateField<T extends DateValue>(props: AriaDateFieldProps<T>,
|
|
|
136
137
|
* A time field allows users to enter and edit time values using a keyboard.
|
|
137
138
|
* Each part of a time value is displayed in an individually editable segment.
|
|
138
139
|
*/
|
|
139
|
-
export function useTimeField<T extends TimeValue>(props: AriaTimeFieldProps<T>, state: DateFieldState, ref: RefObject<
|
|
140
|
+
export function useTimeField<T extends TimeValue>(props: AriaTimeFieldProps<T>, state: DateFieldState, ref: RefObject<Element>): DateFieldAria {
|
|
140
141
|
return useDateField(props, state, ref);
|
|
141
142
|
}
|
package/src/useDatePicker.ts
CHANGED
|
@@ -16,28 +16,29 @@ import {AriaDialogProps} from '@react-types/dialog';
|
|
|
16
16
|
import {CalendarProps} from '@react-types/calendar';
|
|
17
17
|
import {createFocusManager} from '@react-aria/focus';
|
|
18
18
|
import {DatePickerState} from '@react-stately/datepicker';
|
|
19
|
+
import {DOMAttributes} from '@react-types/shared';
|
|
19
20
|
import {filterDOMProps, mergeProps, useDescription, useId} from '@react-aria/utils';
|
|
20
|
-
import {HTMLAttributes, RefObject, useMemo} from 'react';
|
|
21
21
|
// @ts-ignore
|
|
22
22
|
import intlMessages from '../intl/*.json';
|
|
23
|
+
import {RefObject, useMemo} from 'react';
|
|
23
24
|
import {roleSymbol} from './useDateField';
|
|
24
25
|
import {useDatePickerGroup} from './useDatePickerGroup';
|
|
25
26
|
import {useField} from '@react-aria/label';
|
|
26
|
-
import {useLocale,
|
|
27
|
+
import {useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
27
28
|
|
|
28
29
|
export interface DatePickerAria {
|
|
29
30
|
/** Props for the date picker's visible label element, if any. */
|
|
30
|
-
labelProps:
|
|
31
|
+
labelProps: DOMAttributes,
|
|
31
32
|
/** Props for the grouping element containing the date field and button. */
|
|
32
|
-
groupProps:
|
|
33
|
+
groupProps: DOMAttributes,
|
|
33
34
|
/** Props for the date field. */
|
|
34
35
|
fieldProps: AriaDatePickerProps<DateValue>,
|
|
35
36
|
/** Props for the popover trigger button. */
|
|
36
37
|
buttonProps: AriaButtonProps,
|
|
37
38
|
/** Props for the description element, if any. */
|
|
38
|
-
descriptionProps:
|
|
39
|
+
descriptionProps: DOMAttributes,
|
|
39
40
|
/** Props for the error message element, if any. */
|
|
40
|
-
errorMessageProps:
|
|
41
|
+
errorMessageProps: DOMAttributes,
|
|
41
42
|
/** Props for the popover dialog. */
|
|
42
43
|
dialogProps: AriaDialogProps,
|
|
43
44
|
/** Props for the calendar within the popover dialog. */
|
|
@@ -48,10 +49,10 @@ export interface DatePickerAria {
|
|
|
48
49
|
* Provides the behavior and accessibility implementation for a date picker component.
|
|
49
50
|
* A date picker combines a DateField and a Calendar popover to allow users to enter or select a date and time value.
|
|
50
51
|
*/
|
|
51
|
-
export function useDatePicker<T extends DateValue>(props: AriaDatePickerProps<T>, state: DatePickerState, ref: RefObject<
|
|
52
|
+
export function useDatePicker<T extends DateValue>(props: AriaDatePickerProps<T>, state: DatePickerState, ref: RefObject<Element>): DatePickerAria {
|
|
52
53
|
let buttonId = useId();
|
|
53
54
|
let dialogId = useId();
|
|
54
|
-
let
|
|
55
|
+
let stringFormatter = useLocalizedStringFormatter(intlMessages);
|
|
55
56
|
|
|
56
57
|
let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({
|
|
57
58
|
...props,
|
|
@@ -64,7 +65,7 @@ export function useDatePicker<T extends DateValue>(props: AriaDatePickerProps<T>
|
|
|
64
65
|
|
|
65
66
|
let {locale} = useLocale();
|
|
66
67
|
let date = state.formatValue(locale, {month: 'long'});
|
|
67
|
-
let description = date ?
|
|
68
|
+
let description = date ? stringFormatter.format('selectedDateDescription', {date}) : '';
|
|
68
69
|
let descProps = useDescription(description);
|
|
69
70
|
let ariaDescribedBy = [descProps['aria-describedby'], fieldProps['aria-describedby']].filter(Boolean).join(' ') || undefined;
|
|
70
71
|
let domProps = filterDOMProps(props);
|
|
@@ -107,7 +108,7 @@ export function useDatePicker<T extends DateValue>(props: AriaDatePickerProps<T>
|
|
|
107
108
|
...descProps,
|
|
108
109
|
id: buttonId,
|
|
109
110
|
'aria-haspopup': 'dialog',
|
|
110
|
-
'aria-label':
|
|
111
|
+
'aria-label': stringFormatter.format('calendar'),
|
|
111
112
|
'aria-labelledby': `${labelledBy} ${buttonId}`,
|
|
112
113
|
'aria-describedby': ariaDescribedBy,
|
|
113
114
|
onPress: () => state.setOpen(true)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {createFocusManager, getFocusableTreeWalker} from '@react-aria/focus';
|
|
2
2
|
import {DateFieldState, DatePickerState, DateRangePickerState} from '@react-stately/datepicker';
|
|
3
|
-
import {KeyboardEvent} from '@react-types/shared';
|
|
3
|
+
import {FocusableElement, KeyboardEvent} from '@react-types/shared';
|
|
4
4
|
import {mergeProps} from '@react-aria/utils';
|
|
5
5
|
import {RefObject, useMemo} from 'react';
|
|
6
6
|
import {useLocale} from '@react-aria/i18n';
|
|
7
7
|
import {usePress} from '@react-aria/interactions';
|
|
8
8
|
|
|
9
|
-
export function useDatePickerGroup(state: DatePickerState | DateRangePickerState | DateFieldState, ref: RefObject<
|
|
9
|
+
export function useDatePickerGroup(state: DatePickerState | DateRangePickerState | DateFieldState, ref: RefObject<Element>, disableArrowNavigation?: boolean) {
|
|
10
10
|
let {direction} = useLocale();
|
|
11
11
|
let focusManager = useMemo(() => createFocusManager(ref), [ref]);
|
|
12
12
|
|
|
@@ -47,18 +47,18 @@ export function useDatePickerGroup(state: DatePickerState | DateRangePickerState
|
|
|
47
47
|
// Focus the first placeholder segment from the end on mouse down/touch up in the field.
|
|
48
48
|
let focusLast = () => {
|
|
49
49
|
// Try to find the segment prior to the element that was clicked on.
|
|
50
|
-
let target = window.event?.target as
|
|
50
|
+
let target = window.event?.target as FocusableElement;
|
|
51
51
|
let walker = getFocusableTreeWalker(ref.current, {tabbable: true});
|
|
52
52
|
if (target) {
|
|
53
53
|
walker.currentNode = target;
|
|
54
|
-
target = walker.previousNode() as
|
|
54
|
+
target = walker.previousNode() as FocusableElement;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
// If no target found, find the last element from the end.
|
|
58
58
|
if (!target) {
|
|
59
|
-
let last:
|
|
59
|
+
let last: FocusableElement;
|
|
60
60
|
do {
|
|
61
|
-
last = walker.lastChild() as
|
|
61
|
+
last = walker.lastChild() as FocusableElement;
|
|
62
62
|
if (last) {
|
|
63
63
|
target = last;
|
|
64
64
|
}
|
|
@@ -67,7 +67,7 @@ export function useDatePickerGroup(state: DatePickerState | DateRangePickerState
|
|
|
67
67
|
|
|
68
68
|
// Now go backwards until we find an element that is not a placeholder.
|
|
69
69
|
while (target?.hasAttribute('data-placeholder')) {
|
|
70
|
-
let prev = walker.previousNode() as
|
|
70
|
+
let prev = walker.previousNode() as FocusableElement;
|
|
71
71
|
if (prev && prev.hasAttribute('data-placeholder')) {
|
|
72
72
|
target = prev;
|
|
73
73
|
} else {
|
|
@@ -81,6 +81,8 @@ export function useDatePickerGroup(state: DatePickerState | DateRangePickerState
|
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
let {pressProps} = usePress({
|
|
84
|
+
preventFocusOnPress: true,
|
|
85
|
+
allowTextSelectionOnPress: true,
|
|
84
86
|
onPressStart(e) {
|
|
85
87
|
if (e.pointerType === 'mouse') {
|
|
86
88
|
focusLast();
|
|
@@ -15,21 +15,22 @@ import {AriaDatePickerProps, AriaDateRangePickerProps, DateValue} from '@react-t
|
|
|
15
15
|
import {AriaDialogProps} from '@react-types/dialog';
|
|
16
16
|
import {createFocusManager} from '@react-aria/focus';
|
|
17
17
|
import {DateRangePickerState} from '@react-stately/datepicker';
|
|
18
|
+
import {DOMAttributes} from '@react-types/shared';
|
|
18
19
|
import {filterDOMProps, mergeProps, useDescription, useId} from '@react-aria/utils';
|
|
19
20
|
import {focusManagerSymbol, roleSymbol} from './useDateField';
|
|
20
|
-
import {HTMLAttributes, RefObject, useMemo} from 'react';
|
|
21
21
|
// @ts-ignore
|
|
22
22
|
import intlMessages from '../intl/*.json';
|
|
23
23
|
import {RangeCalendarProps} from '@react-types/calendar';
|
|
24
|
+
import {RefObject, useMemo} from 'react';
|
|
24
25
|
import {useDatePickerGroup} from './useDatePickerGroup';
|
|
25
26
|
import {useField} from '@react-aria/label';
|
|
26
|
-
import {useLocale,
|
|
27
|
+
import {useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
27
28
|
|
|
28
29
|
export interface DateRangePickerAria {
|
|
29
30
|
/** Props for the date range picker's visible label element, if any. */
|
|
30
|
-
labelProps:
|
|
31
|
+
labelProps: DOMAttributes,
|
|
31
32
|
/** Props for the grouping element containing the date fields and button. */
|
|
32
|
-
groupProps:
|
|
33
|
+
groupProps: DOMAttributes,
|
|
33
34
|
/** Props for the start date field. */
|
|
34
35
|
startFieldProps: AriaDatePickerProps<DateValue>,
|
|
35
36
|
/** Props for the end date field. */
|
|
@@ -37,9 +38,9 @@ export interface DateRangePickerAria {
|
|
|
37
38
|
/** Props for the popover trigger button. */
|
|
38
39
|
buttonProps: AriaButtonProps,
|
|
39
40
|
/** Props for the description element, if any. */
|
|
40
|
-
descriptionProps:
|
|
41
|
+
descriptionProps: DOMAttributes,
|
|
41
42
|
/** Props for the error message element, if any. */
|
|
42
|
-
errorMessageProps:
|
|
43
|
+
errorMessageProps: DOMAttributes,
|
|
43
44
|
/** Props for the popover dialog. */
|
|
44
45
|
dialogProps: AriaDialogProps,
|
|
45
46
|
/** Props for the range calendar within the popover dialog. */
|
|
@@ -51,8 +52,8 @@ export interface DateRangePickerAria {
|
|
|
51
52
|
* A date range picker combines two DateFields and a RangeCalendar popover to allow
|
|
52
53
|
* users to enter or select a date and time range.
|
|
53
54
|
*/
|
|
54
|
-
export function useDateRangePicker<T extends DateValue>(props: AriaDateRangePickerProps<T>, state: DateRangePickerState, ref: RefObject<
|
|
55
|
-
let
|
|
55
|
+
export function useDateRangePicker<T extends DateValue>(props: AriaDateRangePickerProps<T>, state: DateRangePickerState, ref: RefObject<Element>): DateRangePickerAria {
|
|
56
|
+
let stringFormatter = useLocalizedStringFormatter(intlMessages);
|
|
56
57
|
let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({
|
|
57
58
|
...props,
|
|
58
59
|
labelElementType: 'span'
|
|
@@ -62,16 +63,16 @@ export function useDateRangePicker<T extends DateValue>(props: AriaDateRangePick
|
|
|
62
63
|
|
|
63
64
|
let {locale} = useLocale();
|
|
64
65
|
let range = state.formatValue(locale, {month: 'long'});
|
|
65
|
-
let description = range ?
|
|
66
|
+
let description = range ? stringFormatter.format('selectedRangeDescription', {startDate: range.start, endDate: range.end}) : '';
|
|
66
67
|
let descProps = useDescription(description);
|
|
67
68
|
|
|
68
69
|
let startFieldProps = {
|
|
69
|
-
'aria-label':
|
|
70
|
+
'aria-label': stringFormatter.format('startDate'),
|
|
70
71
|
'aria-labelledby': labelledBy
|
|
71
72
|
};
|
|
72
73
|
|
|
73
74
|
let endFieldProps = {
|
|
74
|
-
'aria-label':
|
|
75
|
+
'aria-label': stringFormatter.format('endDate'),
|
|
75
76
|
'aria-labelledby': labelledBy
|
|
76
77
|
};
|
|
77
78
|
|
|
@@ -120,7 +121,7 @@ export function useDateRangePicker<T extends DateValue>(props: AriaDateRangePick
|
|
|
120
121
|
...descProps,
|
|
121
122
|
id: buttonId,
|
|
122
123
|
'aria-haspopup': 'dialog',
|
|
123
|
-
'aria-label':
|
|
124
|
+
'aria-label': stringFormatter.format('calendar'),
|
|
124
125
|
'aria-labelledby': `${labelledBy} ${buttonId}`,
|
|
125
126
|
'aria-describedby': ariaDescribedBy,
|
|
126
127
|
onPress: () => state.setOpen(true)
|
package/src/useDateSegment.ts
CHANGED
|
@@ -12,17 +12,18 @@
|
|
|
12
12
|
|
|
13
13
|
import {CalendarDate, toCalendar} from '@internationalized/date';
|
|
14
14
|
import {DateFieldState, DateSegment} from '@react-stately/datepicker';
|
|
15
|
+
import {DOMAttributes} from '@react-types/shared';
|
|
15
16
|
import {getScrollParent, isIOS, isMac, mergeProps, scrollIntoView, useEvent, useId, useLabels, useLayoutEffect} from '@react-aria/utils';
|
|
16
17
|
import {hookData} from './useDateField';
|
|
17
18
|
import {NumberParser} from '@internationalized/number';
|
|
18
|
-
import React, {
|
|
19
|
+
import React, {RefObject, useMemo, useRef} from 'react';
|
|
19
20
|
import {useDateFormatter, useFilter, useLocale} from '@react-aria/i18n';
|
|
20
21
|
import {useDisplayNames} from './useDisplayNames';
|
|
21
22
|
import {useSpinButton} from '@react-aria/spinbutton';
|
|
22
23
|
|
|
23
24
|
export interface DateSegmentAria {
|
|
24
25
|
/** Props for the segment element. */
|
|
25
|
-
segmentProps:
|
|
26
|
+
segmentProps: DOMAttributes
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
/**
|
package/src/useDisplayNames.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
// @ts-ignore
|
|
14
14
|
import intlMessages from '../intl/*.json';
|
|
15
|
-
import {
|
|
15
|
+
import {LocalizedStringDictionary} from '@internationalized/string';
|
|
16
16
|
import {useLocale} from '@react-aria/i18n';
|
|
17
17
|
import {useMemo} from 'react';
|
|
18
18
|
|
|
@@ -38,11 +38,11 @@ export function useDisplayNames(): DisplayNames {
|
|
|
38
38
|
|
|
39
39
|
class DisplayNamesPolyfill implements DisplayNames {
|
|
40
40
|
private locale: string;
|
|
41
|
-
private dictionary:
|
|
41
|
+
private dictionary: LocalizedStringDictionary<Field, string>;
|
|
42
42
|
|
|
43
43
|
constructor(locale: string) {
|
|
44
44
|
this.locale = locale;
|
|
45
|
-
this.dictionary = new
|
|
45
|
+
this.dictionary = new LocalizedStringDictionary<Field, string>(intlMessages);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
of(field: Field): string {
|