@react-aria/calendar 3.5.12 → 3.6.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/LICENSE +201 -0
- package/dist/ar-AE.main.js.map +1 -1
- package/dist/ar-AE.module.js.map +1 -1
- package/dist/bg-BG.main.js.map +1 -1
- package/dist/bg-BG.module.js.map +1 -1
- package/dist/cs-CZ.main.js.map +1 -1
- package/dist/cs-CZ.module.js.map +1 -1
- package/dist/da-DK.main.js.map +1 -1
- package/dist/da-DK.module.js.map +1 -1
- package/dist/de-DE.main.js.map +1 -1
- package/dist/de-DE.module.js.map +1 -1
- package/dist/el-GR.main.js.map +1 -1
- package/dist/el-GR.module.js.map +1 -1
- package/dist/en-US.main.js.map +1 -1
- package/dist/en-US.module.js.map +1 -1
- package/dist/es-ES.main.js.map +1 -1
- package/dist/es-ES.module.js.map +1 -1
- package/dist/et-EE.main.js.map +1 -1
- package/dist/et-EE.module.js.map +1 -1
- package/dist/fi-FI.main.js.map +1 -1
- package/dist/fi-FI.module.js.map +1 -1
- package/dist/fr-FR.main.js.map +1 -1
- package/dist/fr-FR.module.js.map +1 -1
- package/dist/he-IL.main.js.map +1 -1
- package/dist/he-IL.module.js.map +1 -1
- package/dist/hr-HR.main.js.map +1 -1
- package/dist/hr-HR.module.js.map +1 -1
- package/dist/hu-HU.main.js.map +1 -1
- package/dist/hu-HU.module.js.map +1 -1
- package/dist/it-IT.main.js.map +1 -1
- package/dist/it-IT.module.js.map +1 -1
- package/dist/ja-JP.main.js.map +1 -1
- package/dist/ja-JP.module.js.map +1 -1
- package/dist/ko-KR.main.js.map +1 -1
- package/dist/ko-KR.module.js.map +1 -1
- package/dist/lt-LT.main.js.map +1 -1
- package/dist/lt-LT.module.js.map +1 -1
- package/dist/lv-LV.main.js.map +1 -1
- package/dist/lv-LV.module.js.map +1 -1
- package/dist/nb-NO.main.js.map +1 -1
- package/dist/nb-NO.module.js.map +1 -1
- package/dist/nl-NL.main.js.map +1 -1
- package/dist/nl-NL.module.js.map +1 -1
- package/dist/pl-PL.main.js.map +1 -1
- package/dist/pl-PL.module.js.map +1 -1
- package/dist/pt-BR.main.js.map +1 -1
- package/dist/pt-BR.module.js.map +1 -1
- package/dist/pt-PT.main.js.map +1 -1
- package/dist/pt-PT.module.js.map +1 -1
- package/dist/ro-RO.main.js.map +1 -1
- package/dist/ro-RO.module.js.map +1 -1
- package/dist/ru-RU.main.js.map +1 -1
- package/dist/ru-RU.module.js.map +1 -1
- package/dist/sk-SK.main.js.map +1 -1
- package/dist/sk-SK.module.js.map +1 -1
- package/dist/sl-SI.main.js.map +1 -1
- package/dist/sl-SI.module.js.map +1 -1
- package/dist/sr-SP.main.js.map +1 -1
- package/dist/sr-SP.module.js.map +1 -1
- package/dist/sv-SE.main.js.map +1 -1
- package/dist/sv-SE.module.js.map +1 -1
- package/dist/tr-TR.main.js.map +1 -1
- package/dist/tr-TR.module.js.map +1 -1
- package/dist/uk-UA.main.js.map +1 -1
- package/dist/uk-UA.module.js.map +1 -1
- package/dist/useCalendarCell.main.js +11 -11
- package/dist/useCalendarCell.main.js.map +1 -1
- package/dist/useCalendarCell.mjs +11 -11
- package/dist/useCalendarCell.module.js +11 -11
- package/dist/useCalendarCell.module.js.map +1 -1
- package/dist/useCalendarGrid.main.js +2 -2
- package/dist/useCalendarGrid.main.js.map +1 -1
- package/dist/useCalendarGrid.mjs +2 -2
- package/dist/useCalendarGrid.module.js +2 -2
- package/dist/useCalendarGrid.module.js.map +1 -1
- package/dist/utils.main.js +2 -1
- package/dist/utils.main.js.map +1 -1
- package/dist/utils.mjs +2 -1
- package/dist/utils.module.js +2 -1
- package/dist/utils.module.js.map +1 -1
- package/dist/zh-CN.main.js.map +1 -1
- package/dist/zh-CN.module.js.map +1 -1
- package/dist/zh-TW.main.js.map +1 -1
- package/dist/zh-TW.module.js.map +1 -1
- package/package.json +15 -14
- package/src/useCalendarCell.ts +13 -13
- package/src/useCalendarGrid.ts +3 -3
- package/src/utils.ts +5 -5
package/src/useCalendarCell.ts
CHANGED
|
@@ -74,7 +74,7 @@ export interface CalendarCellAria {
|
|
|
74
74
|
*/
|
|
75
75
|
export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarState | RangeCalendarState, ref: RefObject<HTMLElement | null>): CalendarCellAria {
|
|
76
76
|
let {date, isDisabled} = props;
|
|
77
|
-
let {errorMessageId, selectedDateDescription} = hookData.get(state)
|
|
77
|
+
let {errorMessageId, selectedDateDescription} = hookData.get(state)!;
|
|
78
78
|
let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/calendar');
|
|
79
79
|
let dateFormatter = useDateFormatter({
|
|
80
80
|
weekday: 'long',
|
|
@@ -89,7 +89,7 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
89
89
|
isDisabled = isDisabled || state.isCellDisabled(date);
|
|
90
90
|
let isUnavailable = state.isCellUnavailable(date);
|
|
91
91
|
let isSelectable = !isDisabled && !isUnavailable;
|
|
92
|
-
let isInvalid = state.isValueInvalid && (
|
|
92
|
+
let isInvalid = state.isValueInvalid && Boolean(
|
|
93
93
|
'highlightedRange' in state
|
|
94
94
|
? !state.anchorDate && state.highlightedRange && date.compare(state.highlightedRange.start) >= 0 && date.compare(state.highlightedRange.end) <= 0
|
|
95
95
|
: state.value && isSameDay(state.value, date)
|
|
@@ -159,7 +159,7 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
159
159
|
|
|
160
160
|
let isAnchorPressed = useRef(false);
|
|
161
161
|
let isRangeBoundaryPressed = useRef(false);
|
|
162
|
-
let touchDragTimerRef = useRef(
|
|
162
|
+
let touchDragTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
|
163
163
|
let {pressProps, isPressed} = usePress({
|
|
164
164
|
// When dragging to select a range, we don't want dragging over the original anchor
|
|
165
165
|
// again to trigger onPressStart. Cancel presses immediately when the pointer exits.
|
|
@@ -195,7 +195,7 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
195
195
|
|
|
196
196
|
let startDragging = () => {
|
|
197
197
|
state.setDragging(true);
|
|
198
|
-
touchDragTimerRef.current =
|
|
198
|
+
touchDragTimerRef.current = undefined;
|
|
199
199
|
|
|
200
200
|
state.selectDate(date);
|
|
201
201
|
state.setFocusedDate(date);
|
|
@@ -215,7 +215,7 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
215
215
|
isRangeBoundaryPressed.current = false;
|
|
216
216
|
isAnchorPressed.current = false;
|
|
217
217
|
clearTimeout(touchDragTimerRef.current);
|
|
218
|
-
touchDragTimerRef.current =
|
|
218
|
+
touchDragTimerRef.current = undefined;
|
|
219
219
|
},
|
|
220
220
|
onPress() {
|
|
221
221
|
// For non-range selection, always select on press up.
|
|
@@ -269,7 +269,7 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
269
269
|
}
|
|
270
270
|
});
|
|
271
271
|
|
|
272
|
-
let tabIndex =
|
|
272
|
+
let tabIndex: number | undefined = undefined;
|
|
273
273
|
if (!isDisabled) {
|
|
274
274
|
tabIndex = isSameDay(date, state.focusedDate) ? 0 : -1;
|
|
275
275
|
}
|
|
@@ -298,14 +298,14 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
298
298
|
calendar: date.calendar.identifier
|
|
299
299
|
});
|
|
300
300
|
|
|
301
|
-
let formattedDate = useMemo(() => cellDateFormatter.formatToParts(nativeDate).find(part => part.type === 'day')
|
|
301
|
+
let formattedDate = useMemo(() => cellDateFormatter.formatToParts(nativeDate).find(part => part.type === 'day')!.value, [cellDateFormatter, nativeDate]);
|
|
302
302
|
|
|
303
303
|
return {
|
|
304
304
|
cellProps: {
|
|
305
305
|
role: 'gridcell',
|
|
306
|
-
'aria-disabled': !isSelectable ||
|
|
307
|
-
'aria-selected': isSelected ||
|
|
308
|
-
'aria-invalid': isInvalid ||
|
|
306
|
+
'aria-disabled': !isSelectable || undefined,
|
|
307
|
+
'aria-selected': isSelected || undefined,
|
|
308
|
+
'aria-invalid': isInvalid || undefined
|
|
309
309
|
},
|
|
310
310
|
buttonProps: mergeProps(pressProps, {
|
|
311
311
|
onFocus() {
|
|
@@ -315,11 +315,11 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
315
315
|
},
|
|
316
316
|
tabIndex,
|
|
317
317
|
role: 'button',
|
|
318
|
-
'aria-disabled': !isSelectable ||
|
|
318
|
+
'aria-disabled': !isSelectable || undefined,
|
|
319
319
|
'aria-label': label,
|
|
320
|
-
'aria-invalid': isInvalid ||
|
|
320
|
+
'aria-invalid': isInvalid || undefined,
|
|
321
321
|
'aria-describedby': [
|
|
322
|
-
isInvalid ? errorMessageId :
|
|
322
|
+
isInvalid ? errorMessageId : undefined,
|
|
323
323
|
descriptionProps['aria-describedby']
|
|
324
324
|
].filter(Boolean).join(' ') || undefined,
|
|
325
325
|
onPointerEnter(e) {
|
package/src/useCalendarGrid.ts
CHANGED
|
@@ -128,7 +128,7 @@ export function useCalendarGrid(props: AriaCalendarGridProps, state: CalendarSta
|
|
|
128
128
|
|
|
129
129
|
let visibleRangeDescription = useVisibleRangeDescription(startDate, endDate, state.timeZone, true);
|
|
130
130
|
|
|
131
|
-
let {ariaLabel, ariaLabelledBy} = hookData.get(state)
|
|
131
|
+
let {ariaLabel, ariaLabelledBy} = hookData.get(state)!;
|
|
132
132
|
let labelProps = useLabels({
|
|
133
133
|
'aria-label': [ariaLabel, visibleRangeDescription].filter(Boolean).join(', '),
|
|
134
134
|
'aria-labelledby': ariaLabelledBy
|
|
@@ -148,8 +148,8 @@ export function useCalendarGrid(props: AriaCalendarGridProps, state: CalendarSta
|
|
|
148
148
|
return {
|
|
149
149
|
gridProps: mergeProps(labelProps, {
|
|
150
150
|
role: 'grid',
|
|
151
|
-
'aria-readonly': state.isReadOnly ||
|
|
152
|
-
'aria-disabled': state.isDisabled ||
|
|
151
|
+
'aria-readonly': state.isReadOnly || undefined,
|
|
152
|
+
'aria-disabled': state.isDisabled || undefined,
|
|
153
153
|
'aria-multiselectable': ('highlightedRange' in state) || undefined,
|
|
154
154
|
onKeyDown,
|
|
155
155
|
onFocus: () => state.setFocused(true),
|
package/src/utils.ts
CHANGED
|
@@ -19,26 +19,26 @@ import {useDateFormatter, useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
|
19
19
|
import {useMemo} from 'react';
|
|
20
20
|
|
|
21
21
|
interface HookData {
|
|
22
|
-
ariaLabel
|
|
23
|
-
ariaLabelledBy
|
|
22
|
+
ariaLabel?: string,
|
|
23
|
+
ariaLabelledBy?: string,
|
|
24
24
|
errorMessageId: string,
|
|
25
25
|
selectedDateDescription: string
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export const hookData = new WeakMap<CalendarState | RangeCalendarState, HookData>();
|
|
29
29
|
|
|
30
|
-
export function getEraFormat(date: CalendarDate): 'short' | undefined {
|
|
30
|
+
export function getEraFormat(date: CalendarDate | undefined): 'short' | undefined {
|
|
31
31
|
return date?.calendar.identifier === 'gregory' && date.era === 'BC' ? 'short' : undefined;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export function useSelectedDateDescription(state: CalendarState | RangeCalendarState) {
|
|
35
35
|
let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/calendar');
|
|
36
36
|
|
|
37
|
-
let start: CalendarDate, end: CalendarDate;
|
|
37
|
+
let start: CalendarDate | undefined, end: CalendarDate | undefined;
|
|
38
38
|
if ('highlightedRange' in state) {
|
|
39
39
|
({start, end} = state.highlightedRange || {});
|
|
40
40
|
} else {
|
|
41
|
-
start = end = state.value;
|
|
41
|
+
start = end = state.value ?? undefined;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
let dateFormatter = useDateFormatter({
|