@react-aria/datepicker 3.15.2 → 3.16.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.
@@ -12,7 +12,7 @@
12
12
 
13
13
  import {CalendarDate, toCalendar} from '@internationalized/date';
14
14
  import {DateFieldState, DateSegment} from '@react-stately/datepicker';
15
- import {getScrollParent, isIOS, isMac, mergeProps, scrollIntoViewport, useEvent, useId, useLabels, useLayoutEffect} from '@react-aria/utils';
15
+ import {getScrollParent, isIOS, isMac, mergeProps, nodeContains, scrollIntoViewport, useEvent, useId, useLabels, useLayoutEffect} from '@react-aria/utils';
16
16
  import {hookData} from './useDateField';
17
17
  import {NumberParser} from '@internationalized/number';
18
18
  import React, {CSSProperties, useMemo, useRef} from 'react';
@@ -57,7 +57,7 @@ export function useDateSegment(segment: DateSegment, state: DateFieldState, ref:
57
57
  // The ARIA spec says aria-valuenow is optional if there's no value, but aXe seems to require it.
58
58
  // This doesn't seem to have any negative effects with real AT since we also use aria-valuetext.
59
59
  // https://github.com/dequelabs/axe-core/issues/3505
60
- value: segment.value,
60
+ value: segment.value ?? undefined,
61
61
  textValue,
62
62
  minValue: segment.minValue,
63
63
  maxValue: segment.maxValue,
@@ -82,15 +82,11 @@ export function useDateSegment(segment: DateSegment, state: DateFieldState, ref:
82
82
  },
83
83
  onIncrementToMax: () => {
84
84
  enteredKeys.current = '';
85
- if (segment.maxValue !== undefined) {
86
- state.setSegment(segment.type, segment.maxValue);
87
- }
85
+ state.incrementToMax(segment.type);
88
86
  },
89
87
  onDecrementToMin: () => {
90
88
  enteredKeys.current = '';
91
- if (segment.minValue !== undefined) {
92
- state.setSegment(segment.type, segment.minValue);
93
- }
89
+ state.decrementToMin(segment.type);
94
90
  }
95
91
  });
96
92
 
@@ -110,7 +106,7 @@ export function useDateSegment(segment: DateSegment, state: DateFieldState, ref:
110
106
  state.setSegment(segment.type, parsed);
111
107
  }
112
108
  enteredKeys.current = newValue;
113
- } else if (segment.type === 'dayPeriod') {
109
+ } else if (segment.type === 'dayPeriod' || segment.type === 'era') {
114
110
  state.clearSegment(segment.type);
115
111
  }
116
112
  };
@@ -193,7 +189,7 @@ export function useDateSegment(segment: DateSegment, state: DateFieldState, ref:
193
189
  if (startsWith(am, key)) {
194
190
  state.setSegment('dayPeriod', 0);
195
191
  } else if (startsWith(pm, key)) {
196
- state.setSegment('dayPeriod', 12);
192
+ state.setSegment('dayPeriod', 1);
197
193
  } else {
198
194
  break;
199
195
  }
@@ -219,26 +215,7 @@ export function useDateSegment(segment: DateSegment, state: DateFieldState, ref:
219
215
 
220
216
  let numberValue = parser.parse(newValue);
221
217
  let segmentValue = numberValue;
222
- let allowsZero = segment.minValue === 0;
223
- if (segment.type === 'hour' && state.dateFormatter.resolvedOptions().hour12) {
224
- switch (state.dateFormatter.resolvedOptions().hourCycle) {
225
- case 'h11':
226
- if (numberValue > 11) {
227
- segmentValue = parser.parse(key);
228
- }
229
- break;
230
- case 'h12':
231
- allowsZero = false;
232
- if (numberValue > 12) {
233
- segmentValue = parser.parse(key);
234
- }
235
- break;
236
- }
237
-
238
- if (segment.value !== undefined && segment.value >= 12 && numberValue > 1) {
239
- numberValue += 12;
240
- }
241
- } else if (segment.maxValue !== undefined && numberValue > segment.maxValue) {
218
+ if (segment.maxValue !== undefined && numberValue > segment.maxValue) {
242
219
  segmentValue = parser.parse(key);
243
220
  }
244
221
 
@@ -246,16 +223,11 @@ export function useDateSegment(segment: DateSegment, state: DateFieldState, ref:
246
223
  return;
247
224
  }
248
225
 
249
- let shouldSetValue = segmentValue !== 0 || allowsZero;
250
- if (shouldSetValue) {
251
- state.setSegment(segment.type, segmentValue);
252
- }
226
+ state.setSegment(segment.type, segmentValue);
253
227
 
254
228
  if (segment.maxValue !== undefined && (Number(numberValue + '0') > segment.maxValue || newValue.length >= String(segment.maxValue).length)) {
255
229
  enteredKeys.current = '';
256
- if (shouldSetValue) {
257
- focusManager.focusNext();
258
- }
230
+ focusManager.focusNext();
259
231
  } else {
260
232
  enteredKeys.current = newValue;
261
233
  }
@@ -281,7 +253,7 @@ export function useDateSegment(segment: DateSegment, state: DateFieldState, ref:
281
253
  // Otherwise, when tapping on a segment in Android Chrome and then entering text,
282
254
  // composition events will be fired that break the DOM structure and crash the page.
283
255
  let selection = window.getSelection();
284
- if (selection?.anchorNode && ref.current?.contains(selection?.anchorNode)) {
256
+ if (selection?.anchorNode && nodeContains(ref.current, selection?.anchorNode)) {
285
257
  selection.collapse(ref.current);
286
258
  }
287
259
  });