@react-aria/calendar 3.2.0 → 3.4.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/module.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {announce as $amWdn$announce} from "@react-aria/live-announcer";
2
- import {filterDOMProps as $amWdn$filterDOMProps, useUpdateEffect as $amWdn$useUpdateEffect, useSlotId as $amWdn$useSlotId, useLabels as $amWdn$useLabels, mergeProps as $amWdn$mergeProps, useEvent as $amWdn$useEvent, useDescription as $amWdn$useDescription, focusWithoutScrolling as $amWdn$focusWithoutScrolling, scrollIntoViewport as $amWdn$scrollIntoViewport, getScrollParent as $amWdn$getScrollParent} from "@react-aria/utils";
2
+ import {filterDOMProps as $amWdn$filterDOMProps, useUpdateEffect as $amWdn$useUpdateEffect, useSlotId as $amWdn$useSlotId, useLabels as $amWdn$useLabels, mergeProps as $amWdn$mergeProps, useEvent as $amWdn$useEvent, useDeepMemo as $amWdn$useDeepMemo, useDescription as $amWdn$useDescription, focusWithoutScrolling as $amWdn$focusWithoutScrolling, scrollIntoViewport as $amWdn$scrollIntoViewport, getScrollParent as $amWdn$getScrollParent} from "@react-aria/utils";
3
3
  import {useLocalizedStringFormatter as $amWdn$useLocalizedStringFormatter, useDateFormatter as $amWdn$useDateFormatter, useLocale as $amWdn$useLocale} from "@react-aria/i18n";
4
- import {useRef as $amWdn$useRef, useMemo as $amWdn$useMemo, useEffect as $amWdn$useEffect} from "react";
4
+ import {useState as $amWdn$useState, useMemo as $amWdn$useMemo, useRef as $amWdn$useRef, useEffect as $amWdn$useEffect} from "react";
5
5
  import {isSameDay as $amWdn$isSameDay, startOfMonth as $amWdn$startOfMonth, endOfMonth as $amWdn$endOfMonth, startOfWeek as $amWdn$startOfWeek, today as $amWdn$today, isEqualDay as $amWdn$isEqualDay, isToday as $amWdn$isToday} from "@internationalized/date";
6
6
  import {usePress as $amWdn$usePress, getInteractionModality as $amWdn$getInteractionModality} from "@react-aria/interactions";
7
7
 
@@ -51,7 +51,7 @@ function $parcel$interopDefault(a) {
51
51
  * OF ANY KIND, either express or implied. See the License for the specific language
52
52
  * governing permissions and limitations under the License.
53
53
  */
54
- var $0fbdc3429b133a50$exports = {};
54
+ var $3904726b442bd9b2$exports = {};
55
55
  var $39324ace0d945f59$exports = {};
56
56
  $39324ace0d945f59$exports = {
57
57
  "dateRange": (args)=>`${args.startDate} إلى ${args.endDate}`,
@@ -630,7 +630,7 @@ $745937250cd4679c$exports = {
630
630
  };
631
631
 
632
632
 
633
- $0fbdc3429b133a50$exports = {
633
+ $3904726b442bd9b2$exports = {
634
634
  "ar-AE": $39324ace0d945f59$exports,
635
635
  "bg-BG": $1830a539e98c7baf$exports,
636
636
  "cs-CZ": $f4b92528965aab97$exports,
@@ -675,7 +675,7 @@ function $a074e1e2d0f0a665$export$134cbb7fb09a9522(date) {
675
675
  return (date === null || date === void 0 ? void 0 : date.calendar.identifier) === "gregory" && date.era === "BC" ? "short" : undefined;
676
676
  }
677
677
  function $a074e1e2d0f0a665$export$b6df97c887c38e1a(state) {
678
- let stringFormatter = (0, $amWdn$useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($0fbdc3429b133a50$exports))));
678
+ let stringFormatter = (0, $amWdn$useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($3904726b442bd9b2$exports))));
679
679
  let start, end;
680
680
  if ("highlightedRange" in state) ({ start: start , end: end } = state.highlightedRange || {});
681
681
  else start = end = state.value;
@@ -716,7 +716,7 @@ function $a074e1e2d0f0a665$export$b6df97c887c38e1a(state) {
716
716
  ]);
717
717
  }
718
718
  function $a074e1e2d0f0a665$export$31afe65d91ef6e8(startDate, endDate, timeZone, isAria) {
719
- let stringFormatter = (0, $amWdn$useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($0fbdc3429b133a50$exports))));
719
+ let stringFormatter = (0, $amWdn$useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($3904726b442bd9b2$exports))));
720
720
  let era = $a074e1e2d0f0a665$export$134cbb7fb09a9522(startDate) || $a074e1e2d0f0a665$export$134cbb7fb09a9522(endDate);
721
721
  let monthFormatter = (0, $amWdn$useDateFormatter)({
722
722
  month: "long",
@@ -764,9 +764,9 @@ function $a074e1e2d0f0a665$var$formatRange(dateFormatter, stringFormatter, start
764
764
  // Now we can combine the parts into start and end strings.
765
765
  let startValue = "";
766
766
  let endValue = "";
767
- for(let i1 = 0; i1 < parts.length; i1++){
768
- if (i1 < separatorIndex) startValue += parts[i1].value;
769
- else if (i1 > separatorIndex) endValue += parts[i1].value;
767
+ for(let i = 0; i < parts.length; i++){
768
+ if (i < separatorIndex) startValue += parts[i].value;
769
+ else if (i > separatorIndex) endValue += parts[i].value;
770
770
  }
771
771
  return stringFormatter.format("dateRange", {
772
772
  startDate: startValue,
@@ -779,7 +779,7 @@ function $a074e1e2d0f0a665$var$formatRange(dateFormatter, stringFormatter, start
779
779
 
780
780
 
781
781
  function $c4acc1de3ab169cf$export$d652b3ea2d672d5b(props, state) {
782
- let stringFormatter = (0, $amWdn$useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($0fbdc3429b133a50$exports))));
782
+ let stringFormatter = (0, $amWdn$useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($3904726b442bd9b2$exports))));
783
783
  let domProps = (0, $amWdn$filterDOMProps)(props);
784
784
  let title = (0, $a074e1e2d0f0a665$export$31afe65d91ef6e8)(state.visibleRange.start, state.visibleRange.end, state.timeZone, false);
785
785
  let visibleRangeDescription = (0, $a074e1e2d0f0a665$export$31afe65d91ef6e8)(state.visibleRange.start, state.visibleRange.end, state.timeZone, true);
@@ -810,16 +810,16 @@ function $c4acc1de3ab169cf$export$d652b3ea2d672d5b(props, state) {
810
810
  selectedDateDescription: selectedDateDescription
811
811
  });
812
812
  // If the next or previous buttons become disabled while they are focused, move focus to the calendar body.
813
- let nextFocused = (0, $amWdn$useRef)(false);
813
+ let [nextFocused, setNextFocused] = (0, $amWdn$useState)(false);
814
814
  let nextDisabled = props.isDisabled || state.isNextVisibleRangeInvalid();
815
- if (nextDisabled && nextFocused.current) {
816
- nextFocused.current = false;
815
+ if (nextDisabled && nextFocused) {
816
+ setNextFocused(false);
817
817
  state.setFocused(true);
818
818
  }
819
- let previousFocused = (0, $amWdn$useRef)(false);
819
+ let [previousFocused, setPreviousFocused] = (0, $amWdn$useState)(false);
820
820
  let previousDisabled = props.isDisabled || state.isPreviousVisibleRangeInvalid();
821
- if (previousDisabled && previousFocused.current) {
822
- previousFocused.current = false;
821
+ if (previousDisabled && previousFocused) {
822
+ setPreviousFocused(false);
823
823
  state.setFocused(true);
824
824
  }
825
825
  let labelProps = (0, $amWdn$useLabels)({
@@ -832,22 +832,20 @@ function $c4acc1de3ab169cf$export$d652b3ea2d672d5b(props, state) {
832
832
  });
833
833
  return {
834
834
  calendarProps: (0, $amWdn$mergeProps)(domProps, labelProps, {
835
- role: "group",
835
+ role: "application",
836
836
  "aria-describedby": props["aria-describedby"] || undefined
837
837
  }),
838
838
  nextButtonProps: {
839
839
  onPress: ()=>state.focusNextPage(),
840
840
  "aria-label": stringFormatter.format("next"),
841
841
  isDisabled: nextDisabled,
842
- onFocus: ()=>nextFocused.current = true,
843
- onBlur: ()=>nextFocused.current = false
842
+ onFocusChange: setNextFocused
844
843
  },
845
844
  prevButtonProps: {
846
845
  onPress: ()=>state.focusPreviousPage(),
847
846
  "aria-label": stringFormatter.format("previous"),
848
847
  isDisabled: previousDisabled,
849
- onFocus: ()=>previousFocused.current = true,
850
- onBlur: ()=>previousFocused.current = false
848
+ onFocusChange: setPreviousFocused
851
849
  },
852
850
  errorMessageProps: {
853
851
  id: errorMessageId
@@ -1004,7 +1002,7 @@ function $e3031d1f8c9d64eb$export$cb95147730a423f5(props, state) {
1004
1002
  "aria-labelledby": ariaLabelledBy
1005
1003
  });
1006
1004
  let dayFormatter = (0, $amWdn$useDateFormatter)({
1007
- weekday: "narrow",
1005
+ weekday: props.weekdayStyle || "narrow",
1008
1006
  timeZone: state.timeZone
1009
1007
  });
1010
1008
  let { locale: locale } = (0, $amWdn$useLocale)();
@@ -1061,11 +1059,10 @@ function $e3031d1f8c9d64eb$export$cb95147730a423f5(props, state) {
1061
1059
 
1062
1060
 
1063
1061
 
1064
-
1065
1062
  function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
1066
1063
  let { date: date , isDisabled: isDisabled } = props;
1067
1064
  let { errorMessageId: errorMessageId , selectedDateDescription: selectedDateDescription } = (0, $a074e1e2d0f0a665$export$653eddfc964b0f8a).get(state);
1068
- let stringFormatter = (0, $amWdn$useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($0fbdc3429b133a50$exports))));
1065
+ let stringFormatter = (0, $amWdn$useLocalizedStringFormatter)((0, (/*@__PURE__*/$parcel$interopDefault($3904726b442bd9b2$exports))));
1069
1066
  let dateFormatter = (0, $amWdn$useDateFormatter)({
1070
1067
  weekday: "long",
1071
1068
  day: "numeric",
@@ -1083,9 +1080,7 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
1083
1080
  if (isInvalid) isSelected = true;
1084
1081
  // For performance, reuse the same date object as before if the new date prop is the same.
1085
1082
  // This allows subsequent useMemo results to be reused.
1086
- let lastDate = (0, $amWdn$useRef)(null);
1087
- if (lastDate.current && (0, $amWdn$isEqualDay)(date, lastDate.current)) date = lastDate.current;
1088
- lastDate.current = date;
1083
+ date = (0, $amWdn$useDeepMemo)(date, (0, $amWdn$isEqualDay));
1089
1084
  let nativeDate = (0, $amWdn$useMemo)(()=>date.toDate(state.timeZone), [
1090
1085
  date,
1091
1086
  state.timeZone
@@ -1236,8 +1231,11 @@ function $36a0ac60f04457c5$export$136073280381448e(props, state, ref) {
1236
1231
  // Scroll into view if navigating with a keyboard, otherwise
1237
1232
  // try not to shift the view under the user's mouse/finger.
1238
1233
  // If in a overlay, scrollIntoViewport will only cause scrolling
1239
- // up to the overlay scroll body to prevent overlay shifting
1240
- if ((0, $amWdn$getInteractionModality)() !== "pointer") (0, $amWdn$scrollIntoViewport)(ref.current, {
1234
+ // up to the overlay scroll body to prevent overlay shifting.
1235
+ // Also only scroll into view if the cell actually got focused.
1236
+ // There are some cases where the cell might be disabled or inside,
1237
+ // an inert container and we don't want to scroll then.
1238
+ if ((0, $amWdn$getInteractionModality)() !== "pointer" && document.activeElement === ref.current) (0, $amWdn$scrollIntoViewport)(ref.current, {
1241
1239
  containingElement: (0, $amWdn$getScrollParent)(ref.current)
1242
1240
  });
1243
1241
  }