@react-aria/calendar 3.0.0-nightly.2238 → 3.0.0-nightly.2258

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.
@@ -21,7 +21,7 @@ import {hookData, useSelectedDateDescription, useVisibleRangeDescription} from '
21
21
  // @ts-ignore
22
22
  import intlMessages from '../intl/*.json';
23
23
  import {useLocalizedStringFormatter} from '@react-aria/i18n';
24
- import {useRef} from 'react';
24
+ import {useState} from 'react';
25
25
 
26
26
  export interface CalendarAria {
27
27
  /** Props for the calendar grouping element. */
@@ -71,17 +71,17 @@ export function useCalendarBase(props: CalendarPropsBase & DOMProps & AriaLabeli
71
71
  });
72
72
 
73
73
  // If the next or previous buttons become disabled while they are focused, move focus to the calendar body.
74
- let nextFocused = useRef(false);
74
+ let [nextFocused, setNextFocused] = useState(false);
75
75
  let nextDisabled = props.isDisabled || state.isNextVisibleRangeInvalid();
76
- if (nextDisabled && nextFocused.current) {
77
- nextFocused.current = false;
76
+ if (nextDisabled && nextFocused) {
77
+ setNextFocused(false);
78
78
  state.setFocused(true);
79
79
  }
80
80
 
81
- let previousFocused = useRef(false);
81
+ let [previousFocused, setPreviousFocused] = useState(false);
82
82
  let previousDisabled = props.isDisabled || state.isPreviousVisibleRangeInvalid();
83
- if (previousDisabled && previousFocused.current) {
84
- previousFocused.current = false;
83
+ if (previousDisabled && previousFocused) {
84
+ setPreviousFocused(false);
85
85
  state.setFocused(true);
86
86
  }
87
87
 
@@ -100,15 +100,13 @@ export function useCalendarBase(props: CalendarPropsBase & DOMProps & AriaLabeli
100
100
  onPress: () => state.focusNextPage(),
101
101
  'aria-label': stringFormatter.format('next'),
102
102
  isDisabled: nextDisabled,
103
- onFocus: () => nextFocused.current = true,
104
- onBlur: () => nextFocused.current = false
103
+ onFocusChange: setNextFocused
105
104
  },
106
105
  prevButtonProps: {
107
106
  onPress: () => state.focusPreviousPage(),
108
107
  'aria-label': stringFormatter.format('previous'),
109
108
  isDisabled: previousDisabled,
110
- onFocus: () => previousFocused.current = true,
111
- onBlur: () => previousFocused.current = false
109
+ onFocusChange: setPreviousFocused
112
110
  },
113
111
  errorMessageProps: {
114
112
  id: errorMessageId
@@ -13,7 +13,7 @@
13
13
  import {CalendarDate, isEqualDay, isSameDay, isToday} from '@internationalized/date';
14
14
  import {CalendarState, RangeCalendarState} from '@react-stately/calendar';
15
15
  import {DOMAttributes} from '@react-types/shared';
16
- import {focusWithoutScrolling, getScrollParent, scrollIntoViewport, useDescription} from '@react-aria/utils';
16
+ import {focusWithoutScrolling, getScrollParent, scrollIntoViewport, useDeepMemo, useDescription} from '@react-aria/utils';
17
17
  import {getEraFormat, hookData} from './utils';
18
18
  import {getInteractionModality, usePress} from '@react-aria/interactions';
19
19
  // @ts-ignore
@@ -102,13 +102,7 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
102
102
 
103
103
  // For performance, reuse the same date object as before if the new date prop is the same.
104
104
  // This allows subsequent useMemo results to be reused.
105
- let lastDate = useRef(null);
106
- if (lastDate.current && isEqualDay(date, lastDate.current)) {
107
- date = lastDate.current;
108
- }
109
-
110
- lastDate.current = date;
111
-
105
+ date = useDeepMemo<CalendarDate>(date, isEqualDay);
112
106
  let nativeDate = useMemo(() => date.toDate(state.timeZone), [date, state.timeZone]);
113
107
 
114
108
  // aria-label should be localize Day of week, Month, Day and Year without Time.
@@ -289,8 +283,11 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
289
283
  // Scroll into view if navigating with a keyboard, otherwise
290
284
  // try not to shift the view under the user's mouse/finger.
291
285
  // If in a overlay, scrollIntoViewport will only cause scrolling
292
- // up to the overlay scroll body to prevent overlay shifting
293
- if (getInteractionModality() !== 'pointer') {
286
+ // up to the overlay scroll body to prevent overlay shifting.
287
+ // Also only scroll into view if the cell actually got focused.
288
+ // There are some cases where the cell might be disabled or inside,
289
+ // an inert container and we don't want to scroll then.
290
+ if (getInteractionModality() !== 'pointer' && document.activeElement === ref.current) {
294
291
  scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});
295
292
  }
296
293
  }