diff --git a/src/PickerInput/RangePicker.tsx b/src/PickerInput/RangePicker.tsx index d7d69c18f..adec59e66 100644 --- a/src/PickerInput/RangePicker.tsx +++ b/src/PickerInput/RangePicker.tsx @@ -260,6 +260,7 @@ function RangePicker( setActiveIndex, nextActiveIndex, activeIndexList, + submitIndexRef, ] = useRangeActive(disabled, allowEmpty, mergedOpen); const onSharedFocus = (event: React.FocusEvent, index?: number) => { @@ -413,7 +414,7 @@ function RangePicker( if (date) { nextValue = fillCalendarValue(date, activeIndex); } - + submitIndexRef.current = activeIndex; // Get next focus index const nextIndex = nextActiveIndex(nextValue); @@ -641,7 +642,7 @@ function RangePicker( needConfirm && // Not change index if is not filled !allowEmpty[lastActiveIndex] && - !hasSubmitValue(lastActiveIndex) && + !hasSubmitValue(lastActiveIndex, submitIndexRef.current) && calendarValue[lastActiveIndex] ) { selectorRef.current.focus({ index: lastActiveIndex }); diff --git a/src/PickerInput/hooks/useRangeActive.ts b/src/PickerInput/hooks/useRangeActive.ts index bf1b9b923..3ce9841fd 100644 --- a/src/PickerInput/hooks/useRangeActive.ts +++ b/src/PickerInput/hooks/useRangeActive.ts @@ -23,12 +23,15 @@ export default function useRangeActive( setActiveIndex: (index: number) => void, nextActiveIndex: NextActive, activeList: number[], + submitIndexRef: React.MutableRefObject, ] { const [activeIndex, setActiveIndex] = React.useState(0); const [focused, setFocused] = React.useState(false); const activeListRef = React.useRef([]); + const submitIndexRef = React.useRef(null); + const lastOperationRef = React.useRef(null); const triggerFocus = (nextFocus: boolean) => { @@ -62,6 +65,7 @@ export default function useRangeActive( useLockEffect(focused || mergedOpen, () => { if (!focused) { activeListRef.current = []; + submitIndexRef.current = null; } }); @@ -79,5 +83,6 @@ export default function useRangeActive( setActiveIndex, nextActiveIndex, activeListRef.current, + submitIndexRef, ]; } diff --git a/src/PickerInput/hooks/useRangeValue.ts b/src/PickerInput/hooks/useRangeValue.ts index 3087ee4df..6db83e048 100644 --- a/src/PickerInput/hooks/useRangeValue.ts +++ b/src/PickerInput/hooks/useRangeValue.ts @@ -186,7 +186,7 @@ export default function useRangeValue boolean, /** Tell `index` has filled value in it */ - hasSubmitValue: (index: number) => boolean, + hasSubmitValue: (index: number, submitIndex: number | null) => boolean, ] { const { // MISC @@ -333,11 +333,8 @@ export default function useRangeValue