Skip to content

Commit

Permalink
fix:adjust hasSubmitValue check for submitIndexRef
Browse files Browse the repository at this point in the history
  • Loading branch information
Zyf665 committed Dec 19, 2024
1 parent 0708b14 commit caaebf8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/PickerInput/RangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ function RangePicker<DateType extends object = any>(
setActiveIndex,
nextActiveIndex,
activeIndexList,
submitIndexRef,
] = useRangeActive(disabled, allowEmpty, mergedOpen);

const onSharedFocus = (event: React.FocusEvent<HTMLElement>, index?: number) => {
Expand Down Expand Up @@ -413,7 +414,7 @@ function RangePicker<DateType extends object = any>(
if (date) {
nextValue = fillCalendarValue(date, activeIndex);
}

submitIndexRef.current = activeIndex;
// Get next focus index
const nextIndex = nextActiveIndex(nextValue);

Expand Down Expand Up @@ -641,7 +642,7 @@ function RangePicker<DateType extends object = any>(
needConfirm &&
// Not change index if is not filled
!allowEmpty[lastActiveIndex] &&
!hasSubmitValue(lastActiveIndex) &&
!hasSubmitValue(lastActiveIndex, submitIndexRef.current) &&
calendarValue[lastActiveIndex]
) {
selectorRef.current.focus({ index: lastActiveIndex });
Expand Down
5 changes: 5 additions & 0 deletions src/PickerInput/hooks/useRangeActive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ export default function useRangeActive<DateType>(
setActiveIndex: (index: number) => void,
nextActiveIndex: NextActive<DateType>,
activeList: number[],
submitIndexRef: React.MutableRefObject<number | null>,
] {
const [activeIndex, setActiveIndex] = React.useState(0);
const [focused, setFocused] = React.useState<boolean>(false);

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

const submitIndexRef = React.useRef<number | null>(null);

const lastOperationRef = React.useRef<OperationType>(null);

const triggerFocus = (nextFocus: boolean) => {
Expand Down Expand Up @@ -62,6 +65,7 @@ export default function useRangeActive<DateType>(
useLockEffect(focused || mergedOpen, () => {
if (!focused) {
activeListRef.current = [];
submitIndexRef.current = null;
}
});

Expand All @@ -79,5 +83,6 @@ export default function useRangeActive<DateType>(
setActiveIndex,
nextActiveIndex,
activeListRef.current,
submitIndexRef,
];
}
9 changes: 3 additions & 6 deletions src/PickerInput/hooks/useRangeValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export default function useRangeValue<ValueType extends DateType[], DateType ext
/** Trigger `onChange` directly without check `disabledDate` */
triggerSubmitChange: (value: ValueType) => boolean,
/** Tell `index` has filled value in it */
hasSubmitValue: (index: number) => boolean,
hasSubmitValue: (index: number, submitIndex: number | null) => boolean,
] {
const {
// MISC
Expand Down Expand Up @@ -333,11 +333,8 @@ export default function useRangeValue<ValueType extends DateType[], DateType ext
);

// ============================ Check =============================
function hasSubmitValue(index: number) {
return (
!!submitValue()[index] &&
isSame(generateConfig, locale, submitValue()[index], getCalendarValue()[index], picker)
);
function hasSubmitValue(index: number, submitIndex: number | null) {
return submitIndex === index;
}

// ============================ Return ============================
Expand Down

0 comments on commit caaebf8

Please sign in to comment.