From 765eb2ce0e1f5428ccc5c40405d9fa85dd79285c Mon Sep 17 00:00:00 2001 From: zyf <1246271707@qq.com> Date: Mon, 15 Jul 2024 21:31:35 +0800 Subject: [PATCH 01/12] =?UTF-8?q?rangPicker=E7=A6=81=E7=94=A8=E6=97=B6=20?= =?UTF-8?q?=E4=B8=8D=E5=9C=A8=E5=AF=B9=E7=A6=81=E7=94=A8=E7=9A=84=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E8=BF=9B=E8=A1=8C=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PickerInput/hooks/useRangeValue.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PickerInput/hooks/useRangeValue.ts b/src/PickerInput/hooks/useRangeValue.ts index 8e1c8a52a..d1f95b765 100644 --- a/src/PickerInput/hooks/useRangeValue.ts +++ b/src/PickerInput/hooks/useRangeValue.ts @@ -270,9 +270,9 @@ export default function useRangeValue>> Invalid const validateDates = // Validate start - (!start || !isInvalidateDate(start, { activeIndex: 0 })) && + (!start || !isInvalidateDate(start, { activeIndex: 0 }) || disabled[0]) && // Validate end - (!end || !isInvalidateDate(end, { from: start, activeIndex: 1 })); + (!end || !isInvalidateDate(end, { from: start, activeIndex: 1 }) || disabled[1]); // >>> Result const allPassed = From 36a047f2382a927b1c6e737bfb34fd0ab0649792 Mon Sep 17 00:00:00 2001 From: zyf <1246271707@qq.com> Date: Tue, 16 Jul 2024 17:31:49 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E7=BC=96=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/range.spec.tsx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/range.spec.tsx b/tests/range.spec.tsx index 3b39edf5e..465f53099 100644 --- a/tests/range.spec.tsx +++ b/tests/range.spec.tsx @@ -294,6 +294,26 @@ describe('Picker.Range', () => { ); }); + it('endDate is selectable when startDate is disabled and validation fails', () => { + const onChange = jest.fn(); + const now = dayjs(); + const disabledDate = (current: Dayjs) => { + return current.diff(now, 'days') < 0; + }; + const { container } = render( + , + ); + const today = new Date().getDate(); + openPicker(container, 1); + selectCell(today, 1); + expect(onChange.mock.calls[0][1]).toEqual(['2023-09-03', dayjs().format('YYYY-MM-DD')]); + }); + it('null value with disabled', () => { // Should not warning with allowEmpty render(); From 6ca53c240c787ae071364284d46599635d29d17a Mon Sep 17 00:00:00 2001 From: zyf <1246271707@qq.com> Date: Tue, 16 Jul 2024 22:24:19 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/range.spec.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/range.spec.tsx b/tests/range.spec.tsx index 465f53099..9679c328e 100644 --- a/tests/range.spec.tsx +++ b/tests/range.spec.tsx @@ -295,6 +295,7 @@ describe('Picker.Range', () => { }); it('endDate is selectable when startDate is disabled and validation fails', () => { + jest.useRealTimers(); const onChange = jest.fn(); const now = dayjs(); const disabledDate = (current: Dayjs) => { @@ -308,9 +309,9 @@ describe('Picker.Range', () => { disabledDate={disabledDate} />, ); - const today = new Date().getDate(); - openPicker(container, 1); - selectCell(today, 1); + const day = new Date().getDate() + openPicker(container,1); + selectCell(day,1); expect(onChange.mock.calls[0][1]).toEqual(['2023-09-03', dayjs().format('YYYY-MM-DD')]); }); From b4a3dca2f70cbb89f95f19c92bbccf59360c692d Mon Sep 17 00:00:00 2001 From: Zyf665 <1246271707@qq.com> Date: Sun, 3 Nov 2024 23:02:37 +0800 Subject: [PATCH 04/12] fix: After the RangePicker sets disabledDate, the date cannot be modified. --- src/PickerInput/hooks/useRangeValue.ts | 5 ++--- tests/range.spec.tsx | 28 +++++++++++++++++++------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/PickerInput/hooks/useRangeValue.ts b/src/PickerInput/hooks/useRangeValue.ts index 8e1c8a52a..14814869f 100644 --- a/src/PickerInput/hooks/useRangeValue.ts +++ b/src/PickerInput/hooks/useRangeValue.ts @@ -270,10 +270,9 @@ export default function useRangeValue>> Invalid const validateDates = // Validate start - (!start || !isInvalidateDate(start, { activeIndex: 0 })) && + (disabled[0] || !start || !isInvalidateDate(start, { activeIndex: 0 })) && // Validate end - (!end || !isInvalidateDate(end, { from: start, activeIndex: 1 })); - + (disabled[1] || !end || !isInvalidateDate(end, { from: start, activeIndex: 1 })); // >>> Result const allPassed = // Null value is from clear button diff --git a/tests/range.spec.tsx b/tests/range.spec.tsx index db5660154..ab31b7c86 100644 --- a/tests/range.spec.tsx +++ b/tests/range.spec.tsx @@ -231,6 +231,25 @@ describe('Picker.Range', () => { expect(baseElement.querySelector('.rc-picker-dropdown-hidden')).toBeTruthy(); }); + it('should not be checked if the value is disabled', () => { + const onChange = jest.fn(); + const { container } = render( + date <= dayjs('2024-11-20').endOf('day')} + onChange={onChange} + />, + ); + + openPicker(container, 1); + selectCell('21', 1); + expect(onChange).toHaveBeenCalledWith( + [expect.anything(), expect.anything()], + ['2024-10-28', '2024-11-21'], + ); + }); + it('should close panel when finish first choose with showTime = true and disabled = [false, true]', () => { const { baseElement } = render(); expect(baseElement.querySelectorAll('.rc-picker-input')).toHaveLength(2); @@ -541,7 +560,7 @@ describe('Picker.Range', () => { it('pass tabIndex', () => { const { container } = render(
- +
, ); @@ -705,12 +724,7 @@ describe('Picker.Range', () => { }); it('prefix', () => { - render( - } - allowClear - />, - ); + render(} allowClear />); expect(document.querySelector('.prefix')).toBeInTheDocument(); }); From 17e849dee6d3231b1f7b6dc60d33058d5784dc21 Mon Sep 17 00:00:00 2001 From: Zyf665 <1246271707@qq.com> Date: Mon, 4 Nov 2024 15:26:53 +0800 Subject: [PATCH 05/12] Add test case --- tests/range.spec.tsx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/range.spec.tsx b/tests/range.spec.tsx index ab31b7c86..87cef745b 100644 --- a/tests/range.spec.tsx +++ b/tests/range.spec.tsx @@ -231,7 +231,7 @@ describe('Picker.Range', () => { expect(baseElement.querySelector('.rc-picker-dropdown-hidden')).toBeTruthy(); }); - it('should not be checked if the value is disabled', () => { + it('should not be checked if the startDate is disabled', () => { const onChange = jest.fn(); const { container } = render( { ['2024-10-28', '2024-11-21'], ); }); + it('should not be checked if the endDate is disabled', () => { + const onChange = jest.fn(); + const { container } = render( + date >= dayjs('2024-11-10').endOf('day')} + onChange={onChange} + />, + ); + + openPicker(container, 0); + selectCell('21', 0); + expect(onChange).toHaveBeenCalledWith( + [expect.anything(), expect.anything()], + ['2024-10-21', '2024-11-20'], + ); + }); it('should close panel when finish first choose with showTime = true and disabled = [false, true]', () => { const { baseElement } = render(); From 1ed4d1c35acb530a4b194cdeb489a6b1c1f617a1 Mon Sep 17 00:00:00 2001 From: zyf <1246271707@qq.com> Date: Mon, 25 Nov 2024 22:16:02 +0800 Subject: [PATCH 06/12] fix: returns right dates onChange when manually change date time without pressing OK button --- src/PickerInput/hooks/useRangeValue.ts | 10 +++--- src/utils/miscUtil.ts | 6 ++++ tests/range.spec.tsx | 50 +++++++++++++++----------- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/src/PickerInput/hooks/useRangeValue.ts b/src/PickerInput/hooks/useRangeValue.ts index bf33d1c6e..bbd5f50c8 100644 --- a/src/PickerInput/hooks/useRangeValue.ts +++ b/src/PickerInput/hooks/useRangeValue.ts @@ -4,7 +4,7 @@ import type { GenerateConfig } from '../../generate'; import useSyncState from '../../hooks/useSyncState'; import type { BaseInfo, FormatType, Locale, ReplaceListType } from '../../interface'; import { formatValue, isSame, isSameTimestamp } from '../../utils/dateUtil'; -import { fillIndex } from '../../utils/miscUtil'; +import { fillRangeValues } from '../../utils/miscUtil'; import type { RangePickerProps } from '../RangePicker'; import type { ReplacedPickerProps } from '../SinglePicker'; import useLockEffect from './useLockEffect'; @@ -142,7 +142,6 @@ export function useInnerValue { - const nextSubmitValue = fillIndex(submitValue(), index, getCalendarValue()[index]); + const flushSubmit = useEvent((_: number, needTriggerChange: boolean) => { + const start = getCalendarValue()[0]; + const end = getCalendarValue()[1]; + + const nextSubmitValue = fillRangeValues(submitValue(), start, end); setSubmitValue(nextSubmitValue); if (needTriggerChange) { diff --git a/src/utils/miscUtil.ts b/src/utils/miscUtil.ts index e2d5efef9..463ccc0a5 100644 --- a/src/utils/miscUtil.ts +++ b/src/utils/miscUtil.ts @@ -26,6 +26,12 @@ export function fillIndex(ori: T, index: number, value: T[numbe return clone; } +export function fillRangeValues(ori: T, start: T[number], end: T[number]): T { + const clone = [...ori] as T; + [clone[0], clone[1]] = [start, end]; + + return clone; +} /** Pick props from the key list. Will filter empty value */ export function pickProps(props: T, keys?: (keyof T)[] | readonly (keyof T)[]) { const clone = {} as T; diff --git a/tests/range.spec.tsx b/tests/range.spec.tsx index 3cace2971..14c7741f4 100644 --- a/tests/range.spec.tsx +++ b/tests/range.spec.tsx @@ -333,27 +333,6 @@ describe('Picker.Range', () => { ); }); - it('endDate is selectable when startDate is disabled and validation fails', () => { - jest.useRealTimers(); - const onChange = jest.fn(); - const now = dayjs(); - const disabledDate = (current: Dayjs) => { - return current.diff(now, 'days') < 0; - }; - const { container } = render( - , - ); - const day = new Date().getDate() - openPicker(container,1); - selectCell(day,1); - expect(onChange.mock.calls[0][1]).toEqual(['2023-09-03', dayjs().format('YYYY-MM-DD')]); - }); - it('null value with disabled', () => { // Should not warning with allowEmpty render(); @@ -1038,6 +1017,35 @@ describe('Picker.Range', () => { expect(document.querySelector('.rc-picker-month-panel')).toBeTruthy(); }); + it('returns right dates onChange when manually change date time without pressing OK button', () => { + const onChange = jest.fn(); + + const { container } = render(); + openPicker(container); + selectCell(15); + fireEvent.click(document.querySelector('ul').querySelector('li')); + fireEvent.click(document.querySelector('.rc-picker-ok button')); + + selectCell(16); + fireEvent.click(document.querySelector('ul').querySelector('li')); + fireEvent.click(document.querySelector('.rc-picker-ok button')); + + expect(onChange).toHaveBeenCalledWith(expect.anything(), [ + '1990-09-15 00:00:00', + '1990-09-16 00:00:00', + ]); + + onChange.mockReset(); + openPicker(container, 0); + selectCell(1); + openPicker(container, 1); + selectCell(2); + fireEvent.click(document.querySelector('.rc-picker-ok button')); + expect(onChange).toHaveBeenCalledWith(expect.anything(), [ + '1990-09-01 00:00:00', + '1990-09-02 00:00:00', + ]); + }); describe('reorder onChange logic', () => { it('datetime should reorder in onChange if start is after end in same date', () => { const onChange = jest.fn(); From bc2c3a1f08f2685f2bc354e56dd1a202185daefa Mon Sep 17 00:00:00 2001 From: Zyf665 <1246271707@qq.com> Date: Tue, 26 Nov 2024 15:06:20 +0800 Subject: [PATCH 07/12] fix:returns wrong dates onChange when manually change date time without pressing OK button --- src/PickerInput/hooks/useRangeValue.ts | 14 +++++------ tests/new-range.spec.tsx | 34 ++++++++++++++++++++++++++ tests/range.spec.tsx | 29 ---------------------- 3 files changed, 41 insertions(+), 36 deletions(-) diff --git a/src/PickerInput/hooks/useRangeValue.ts b/src/PickerInput/hooks/useRangeValue.ts index bbd5f50c8..3087ee4df 100644 --- a/src/PickerInput/hooks/useRangeValue.ts +++ b/src/PickerInput/hooks/useRangeValue.ts @@ -4,7 +4,7 @@ import type { GenerateConfig } from '../../generate'; import useSyncState from '../../hooks/useSyncState'; import type { BaseInfo, FormatType, Locale, ReplaceListType } from '../../interface'; import { formatValue, isSame, isSameTimestamp } from '../../utils/dateUtil'; -import { fillRangeValues } from '../../utils/miscUtil'; +import { fillIndex } from '../../utils/miscUtil'; import type { RangePickerProps } from '../RangePicker'; import type { ReplacedPickerProps } from '../SinglePicker'; import useLockEffect from './useLockEffect'; @@ -301,11 +301,8 @@ export default function useRangeValue { - const start = getCalendarValue()[0]; - const end = getCalendarValue()[1]; - - const nextSubmitValue = fillRangeValues(submitValue(), start, end); + const flushSubmit = useEvent((index: number, needTriggerChange: boolean) => { + const nextSubmitValue = fillIndex(submitValue(), index, getCalendarValue()[index]); setSubmitValue(nextSubmitValue); if (needTriggerChange) { @@ -337,7 +334,10 @@ export default function useRangeValue { expect(onChange).toHaveBeenCalledWith(expect.anything(), ['06:00:00', '11:00:00']); }); + it('Field switch should be locked even when the field already has the values', () => { + const onChange = jest.fn(); + + const { container } = render(); + openPicker(container); + selectCell(15); + fireEvent.click(document.querySelector('ul').querySelector('li')); + fireEvent.click(document.querySelector('.rc-picker-ok button')); + + selectCell(16); + fireEvent.click(document.querySelector('ul').querySelector('li')); + fireEvent.click(document.querySelector('.rc-picker-ok button')); + + expect(onChange).toHaveBeenCalledWith(expect.anything(), [ + '1990-09-15 00:00:00', + '1990-09-16 00:00:00', + ]); + + onChange.mockReset(); + openPicker(container, 0); + selectCell(1); + openPicker(container, 1); + expect(container.querySelectorAll('input')[0]).toHaveFocus(); + expect(container.querySelectorAll('input')[1]).not.toHaveFocus(); + + fireEvent.click(document.querySelector('.rc-picker-ok button')); + selectCell(2); + fireEvent.click(document.querySelector('.rc-picker-ok button')); + expect(onChange).toHaveBeenCalledWith(expect.anything(), [ + '1990-09-01 00:00:00', + '1990-09-02 00:00:00', + ]); + }); + it('double click to confirm if needConfirm', () => { const onChange = jest.fn(); diff --git a/tests/range.spec.tsx b/tests/range.spec.tsx index 14c7741f4..791a7e501 100644 --- a/tests/range.spec.tsx +++ b/tests/range.spec.tsx @@ -1017,35 +1017,6 @@ describe('Picker.Range', () => { expect(document.querySelector('.rc-picker-month-panel')).toBeTruthy(); }); - it('returns right dates onChange when manually change date time without pressing OK button', () => { - const onChange = jest.fn(); - - const { container } = render(); - openPicker(container); - selectCell(15); - fireEvent.click(document.querySelector('ul').querySelector('li')); - fireEvent.click(document.querySelector('.rc-picker-ok button')); - - selectCell(16); - fireEvent.click(document.querySelector('ul').querySelector('li')); - fireEvent.click(document.querySelector('.rc-picker-ok button')); - - expect(onChange).toHaveBeenCalledWith(expect.anything(), [ - '1990-09-15 00:00:00', - '1990-09-16 00:00:00', - ]); - - onChange.mockReset(); - openPicker(container, 0); - selectCell(1); - openPicker(container, 1); - selectCell(2); - fireEvent.click(document.querySelector('.rc-picker-ok button')); - expect(onChange).toHaveBeenCalledWith(expect.anything(), [ - '1990-09-01 00:00:00', - '1990-09-02 00:00:00', - ]); - }); describe('reorder onChange logic', () => { it('datetime should reorder in onChange if start is after end in same date', () => { const onChange = jest.fn(); From 922b1b4b56dba65722da94a9d623dba135892c7e Mon Sep 17 00:00:00 2001 From: Zyf665 <1246271707@qq.com> Date: Tue, 26 Nov 2024 15:22:27 +0800 Subject: [PATCH 08/12] fix:returns wrong dates onChange when manually change date time without pressing OK button --- src/utils/miscUtil.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/utils/miscUtil.ts b/src/utils/miscUtil.ts index 463ccc0a5..e2d5efef9 100644 --- a/src/utils/miscUtil.ts +++ b/src/utils/miscUtil.ts @@ -26,12 +26,6 @@ export function fillIndex(ori: T, index: number, value: T[numbe return clone; } -export function fillRangeValues(ori: T, start: T[number], end: T[number]): T { - const clone = [...ori] as T; - [clone[0], clone[1]] = [start, end]; - - return clone; -} /** Pick props from the key list. Will filter empty value */ export function pickProps(props: T, keys?: (keyof T)[] | readonly (keyof T)[]) { const clone = {} as T; From df6676bd2bc8e4d9be303acc1d43eb0bcac4beba Mon Sep 17 00:00:00 2001 From: Zyf665 <1246271707@qq.com> Date: Tue, 26 Nov 2024 15:50:46 +0800 Subject: [PATCH 09/12] fix:modify test cases --- tests/new-range.spec.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/new-range.spec.tsx b/tests/new-range.spec.tsx index 05d404bb6..3d92fee62 100644 --- a/tests/new-range.spec.tsx +++ b/tests/new-range.spec.tsx @@ -722,11 +722,9 @@ describe('NewPicker.Range', () => { const { container } = render(); openPicker(container); selectCell(15); - fireEvent.click(document.querySelector('ul').querySelector('li')); fireEvent.click(document.querySelector('.rc-picker-ok button')); selectCell(16); - fireEvent.click(document.querySelector('ul').querySelector('li')); fireEvent.click(document.querySelector('.rc-picker-ok button')); expect(onChange).toHaveBeenCalledWith(expect.anything(), [ @@ -742,6 +740,8 @@ describe('NewPicker.Range', () => { expect(container.querySelectorAll('input')[1]).not.toHaveFocus(); fireEvent.click(document.querySelector('.rc-picker-ok button')); + openPicker(container, 1); + expect(container.querySelectorAll('input')[1]).toHaveFocus(); selectCell(2); fireEvent.click(document.querySelector('.rc-picker-ok button')); expect(onChange).toHaveBeenCalledWith(expect.anything(), [ From caaebf85eb1e0b8c2605bd0efc98df34e133e789 Mon Sep 17 00:00:00 2001 From: Zyf665 <1246271707@qq.com> Date: Thu, 19 Dec 2024 10:20:29 +0800 Subject: [PATCH 10/12] fix:adjust hasSubmitValue check for submitIndexRef --- src/PickerInput/RangePicker.tsx | 5 +++-- src/PickerInput/hooks/useRangeActive.ts | 5 +++++ src/PickerInput/hooks/useRangeValue.ts | 9 +++------ 3 files changed, 11 insertions(+), 8 deletions(-) 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 Date: Thu, 19 Dec 2024 15:24:37 +0800 Subject: [PATCH 11/12] fix:add hasActiveSubmitValue check for submitIndexRef --- src/PickerInput/RangePicker.tsx | 9 ++++----- src/PickerInput/hooks/useRangeActive.ts | 18 +++++++++++++----- src/PickerInput/hooks/useRangeValue.ts | 6 +++--- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/PickerInput/RangePicker.tsx b/src/PickerInput/RangePicker.tsx index adec59e66..5c01e303d 100644 --- a/src/PickerInput/RangePicker.tsx +++ b/src/PickerInput/RangePicker.tsx @@ -260,7 +260,8 @@ function RangePicker( setActiveIndex, nextActiveIndex, activeIndexList, - submitIndexRef, + updateSubmitIndex, + hasActiveSubmitValue, ] = useRangeActive(disabled, allowEmpty, mergedOpen); const onSharedFocus = (event: React.FocusEvent, index?: number) => { @@ -326,8 +327,6 @@ function RangePicker( flushSubmit, /** Trigger `onChange` directly without check `disabledDate` */ triggerSubmitChange, - /** Tell `index` has filled value in it */ - hasSubmitValue, ] = useRangeValue, DateType>( filledProps, mergedValue, @@ -414,7 +413,7 @@ function RangePicker( if (date) { nextValue = fillCalendarValue(date, activeIndex); } - submitIndexRef.current = activeIndex; + updateSubmitIndex(activeIndex); // Get next focus index const nextIndex = nextActiveIndex(nextValue); @@ -642,7 +641,7 @@ function RangePicker( needConfirm && // Not change index if is not filled !allowEmpty[lastActiveIndex] && - !hasSubmitValue(lastActiveIndex, submitIndexRef.current) && + !hasActiveSubmitValue(lastActiveIndex) && calendarValue[lastActiveIndex] ) { selectorRef.current.focus({ index: lastActiveIndex }); diff --git a/src/PickerInput/hooks/useRangeActive.ts b/src/PickerInput/hooks/useRangeActive.ts index 3ce9841fd..6eec27467 100644 --- a/src/PickerInput/hooks/useRangeActive.ts +++ b/src/PickerInput/hooks/useRangeActive.ts @@ -23,17 +23,24 @@ export default function useRangeActive( setActiveIndex: (index: number) => void, nextActiveIndex: NextActive, activeList: number[], - submitIndexRef: React.MutableRefObject, + updateSubmitIndex: (index: number | null) => void, + hasActiveSubmitValue: (index: number) => boolean, ] { 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 updateSubmitIndex = (index: number | null) => { + submitIndexRef.current = index; + }; + + const hasActiveSubmitValue = (index: number) => { + return submitIndexRef.current === index; + }; + const triggerFocus = (nextFocus: boolean) => { setFocused(nextFocus); }; @@ -65,7 +72,7 @@ export default function useRangeActive( useLockEffect(focused || mergedOpen, () => { if (!focused) { activeListRef.current = []; - submitIndexRef.current = null; + updateSubmitIndex(null); } }); @@ -83,6 +90,7 @@ export default function useRangeActive( setActiveIndex, nextActiveIndex, activeListRef.current, - submitIndexRef, + updateSubmitIndex, + hasActiveSubmitValue, ]; } diff --git a/src/PickerInput/hooks/useRangeValue.ts b/src/PickerInput/hooks/useRangeValue.ts index 6db83e048..55f573714 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, submitIndex: number | null) => boolean, + hasSubmitValue: (index: number) => boolean, ] { const { // MISC @@ -333,8 +333,8 @@ export default function useRangeValue Date: Thu, 19 Dec 2024 20:33:56 +0800 Subject: [PATCH 12/12] fix:delete hasSubmitValue check --- src/PickerInput/hooks/useRangeValue.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/PickerInput/hooks/useRangeValue.ts b/src/PickerInput/hooks/useRangeValue.ts index 55f573714..880a0aee6 100644 --- a/src/PickerInput/hooks/useRangeValue.ts +++ b/src/PickerInput/hooks/useRangeValue.ts @@ -185,8 +185,6 @@ export default function useRangeValue void, /** Trigger `onChange` directly without check `disabledDate` */ triggerSubmitChange: (value: ValueType) => boolean, - /** Tell `index` has filled value in it */ - hasSubmitValue: (index: number) => boolean, ] { const { // MISC @@ -332,11 +330,6 @@ export default function useRangeValue