Skip to content

Commit f3d6a4d

Browse files
committed
fix:add hasActiveSubmitValue check for submitIndexRef
1 parent caaebf8 commit f3d6a4d

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

src/PickerInput/RangePicker.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ function RangePicker<DateType extends object = any>(
260260
setActiveIndex,
261261
nextActiveIndex,
262262
activeIndexList,
263-
submitIndexRef,
263+
updateSubmitIndex,
264+
hasActiveSubmitValue,
264265
] = useRangeActive(disabled, allowEmpty, mergedOpen);
265266

266267
const onSharedFocus = (event: React.FocusEvent<HTMLElement>, index?: number) => {
@@ -326,8 +327,6 @@ function RangePicker<DateType extends object = any>(
326327
flushSubmit,
327328
/** Trigger `onChange` directly without check `disabledDate` */
328329
triggerSubmitChange,
329-
/** Tell `index` has filled value in it */
330-
hasSubmitValue,
331330
] = useRangeValue<RangeValueType<DateType>, DateType>(
332331
filledProps,
333332
mergedValue,
@@ -414,7 +413,7 @@ function RangePicker<DateType extends object = any>(
414413
if (date) {
415414
nextValue = fillCalendarValue(date, activeIndex);
416415
}
417-
submitIndexRef.current = activeIndex;
416+
updateSubmitIndex(activeIndex);
418417
// Get next focus index
419418
const nextIndex = nextActiveIndex(nextValue);
420419

@@ -642,7 +641,7 @@ function RangePicker<DateType extends object = any>(
642641
needConfirm &&
643642
// Not change index if is not filled
644643
!allowEmpty[lastActiveIndex] &&
645-
!hasSubmitValue(lastActiveIndex, submitIndexRef.current) &&
644+
!hasActiveSubmitValue(lastActiveIndex) &&
646645
calendarValue[lastActiveIndex]
647646
) {
648647
selectorRef.current.focus({ index: lastActiveIndex });

src/PickerInput/hooks/useRangeActive.ts

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

3132
const activeListRef = React.useRef<number[]>([]);
32-
3333
const submitIndexRef = React.useRef<number | null>(null);
34-
3534
const lastOperationRef = React.useRef<OperationType>(null);
3635

36+
const updateSubmitIndex = (index: number | null) => {
37+
submitIndexRef.current = index;
38+
};
39+
40+
const hasActiveSubmitValue = (index: number) => {
41+
return submitIndexRef.current === index;
42+
};
43+
3744
const triggerFocus = (nextFocus: boolean) => {
3845
setFocused(nextFocus);
3946
};
@@ -65,7 +72,7 @@ export default function useRangeActive<DateType>(
6572
useLockEffect(focused || mergedOpen, () => {
6673
if (!focused) {
6774
activeListRef.current = [];
68-
submitIndexRef.current = null;
75+
updateSubmitIndex(null);
6976
}
7077
});
7178

@@ -83,6 +90,7 @@ export default function useRangeActive<DateType>(
8390
setActiveIndex,
8491
nextActiveIndex,
8592
activeListRef.current,
86-
submitIndexRef,
93+
updateSubmitIndex,
94+
hasActiveSubmitValue,
8795
];
8896
}

src/PickerInput/hooks/useRangeValue.ts

Lines changed: 3 additions & 3 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, submitIndex: number | null) => boolean,
189+
hasSubmitValue: (index: number) => boolean,
190190
] {
191191
const {
192192
// MISC
@@ -333,8 +333,8 @@ export default function useRangeValue<ValueType extends DateType[], DateType ext
333333
);
334334

335335
// ============================ Check =============================
336-
function hasSubmitValue(index: number, submitIndex: number | null) {
337-
return submitIndex === index;
336+
function hasSubmitValue(index: number) {
337+
return !!submitValue()[index];
338338
}
339339

340340
// ============================ Return ============================

0 commit comments

Comments
 (0)