diff --git a/docs/examples/range.tsx b/docs/examples/range.tsx index 23f50ea00..c03e5d0e0 100644 --- a/docs/examples/range.tsx +++ b/docs/examples/range.tsx @@ -213,6 +213,19 @@ export default () => { disabledDate={disabledDate} /> +
+

needConfirm is false

+ + {...sharedProps} + value={undefined} + locale={zhCN} + needConfirm={false} + picker="time" + ranges={{ + test: [moment(), moment().add(1, 'hour')], + }} + /> +
); diff --git a/src/PickerInput/Popup/index.tsx b/src/PickerInput/Popup/index.tsx index b68fdf2af..cb30ac1ab 100644 --- a/src/PickerInput/Popup/index.tsx +++ b/src/PickerInput/Popup/index.tsx @@ -34,6 +34,8 @@ export interface PopupProps(props: PopupProps(props: PopupProps(props: PopupProps Math.max(0, times - 1)); + // This is a workaround to bypass the inconsistent useEffect behavior in React 18. + // When wrapperRef.current.getBoundingClientRect() fails to calculate the position correctly, it enters the retry logic. + // Under normal circumstances, retryTimes - 1 should equal 9, and useEffect would re-execute the side effect if dependencies change. + // However, in React 18, the side effect is no longer re-executed in such cases. + // By subtracting the index of the currently active input field (index, which is either 0 or 1), we compensate for this additional execution. + // Related issue: https://github.com/ant-design/ant-design/issues/54885 + setRetryTimes((times) => Math.max(0, times - index - 1)); return; } @@ -138,7 +145,16 @@ export default function Popup(props: PopupProps(list: T[]) { diff --git a/src/PickerInput/RangePicker.tsx b/src/PickerInput/RangePicker.tsx index 97d4f335b..0d84132fe 100644 --- a/src/PickerInput/RangePicker.tsx +++ b/src/PickerInput/RangePicker.tsx @@ -592,6 +592,7 @@ function RangePicker( range multiplePanel={multiplePanel} activeInfo={activeInfo} + index={activeIndex} // Disabled disabledDate={mergedDisabledDate} // Focus diff --git a/src/PickerInput/SinglePicker.tsx b/src/PickerInput/SinglePicker.tsx index 09e5ca32e..142c88b50 100644 --- a/src/PickerInput/SinglePicker.tsx +++ b/src/PickerInput/SinglePicker.tsx @@ -513,6 +513,7 @@ function Picker( // Focus onFocus={onPanelFocus} onBlur={onSharedBlur} + index={activeIndex} // Mode picker={picker} mode={mergedMode}