Skip to content

Commit caaebf8

Browse files
committed
fix:adjust hasSubmitValue check for submitIndexRef
1 parent 0708b14 commit caaebf8

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/PickerInput/RangePicker.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ function RangePicker<DateType extends object = any>(
260260
setActiveIndex,
261261
nextActiveIndex,
262262
activeIndexList,
263+
submitIndexRef,
263264
] = useRangeActive(disabled, allowEmpty, mergedOpen);
264265

265266
const onSharedFocus = (event: React.FocusEvent<HTMLElement>, index?: number) => {
@@ -413,7 +414,7 @@ function RangePicker<DateType extends object = any>(
413414
if (date) {
414415
nextValue = fillCalendarValue(date, activeIndex);
415416
}
416-
417+
submitIndexRef.current = activeIndex;
417418
// Get next focus index
418419
const nextIndex = nextActiveIndex(nextValue);
419420

@@ -641,7 +642,7 @@ function RangePicker<DateType extends object = any>(
641642
needConfirm &&
642643
// Not change index if is not filled
643644
!allowEmpty[lastActiveIndex] &&
644-
!hasSubmitValue(lastActiveIndex) &&
645+
!hasSubmitValue(lastActiveIndex, submitIndexRef.current) &&
645646
calendarValue[lastActiveIndex]
646647
) {
647648
selectorRef.current.focus({ index: lastActiveIndex });

src/PickerInput/hooks/useRangeActive.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ export default function useRangeActive<DateType>(
2323
setActiveIndex: (index: number) => void,
2424
nextActiveIndex: NextActive<DateType>,
2525
activeList: number[],
26+
submitIndexRef: React.MutableRefObject<number | null>,
2627
] {
2728
const [activeIndex, setActiveIndex] = React.useState(0);
2829
const [focused, setFocused] = React.useState<boolean>(false);
2930

3031
const activeListRef = React.useRef<number[]>([]);
3132

33+
const submitIndexRef = React.useRef<number | null>(null);
34+
3235
const lastOperationRef = React.useRef<OperationType>(null);
3336

3437
const triggerFocus = (nextFocus: boolean) => {
@@ -62,6 +65,7 @@ export default function useRangeActive<DateType>(
6265
useLockEffect(focused || mergedOpen, () => {
6366
if (!focused) {
6467
activeListRef.current = [];
68+
submitIndexRef.current = null;
6569
}
6670
});
6771

@@ -79,5 +83,6 @@ export default function useRangeActive<DateType>(
7983
setActiveIndex,
8084
nextActiveIndex,
8185
activeListRef.current,
86+
submitIndexRef,
8287
];
8388
}

src/PickerInput/hooks/useRangeValue.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export default function useRangeValue<ValueType extends DateType[], DateType ext
186186
/** Trigger `onChange` directly without check `disabledDate` */
187187
triggerSubmitChange: (value: ValueType) => boolean,
188188
/** Tell `index` has filled value in it */
189-
hasSubmitValue: (index: number) => boolean,
189+
hasSubmitValue: (index: number, submitIndex: number | null) => boolean,
190190
] {
191191
const {
192192
// MISC
@@ -333,11 +333,8 @@ export default function useRangeValue<ValueType extends DateType[], DateType ext
333333
);
334334

335335
// ============================ Check =============================
336-
function hasSubmitValue(index: number) {
337-
return (
338-
!!submitValue()[index] &&
339-
isSame(generateConfig, locale, submitValue()[index], getCalendarValue()[index], picker)
340-
);
336+
function hasSubmitValue(index: number, submitIndex: number | null) {
337+
return submitIndex === index;
341338
}
342339

343340
// ============================ Return ============================

0 commit comments

Comments
 (0)