-
-
Notifications
You must be signed in to change notification settings - Fork 333
fix: Fix Popup localization issue when NeedConfirm=false #941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -34,6 +34,8 @@ export interface PopupProps<DateType extends object = any, PresetValue = DateTyp | |||||
activeInfo?: [activeInputLeft: number, activeInputRight: number, selectorWidth: number]; | ||||||
// Direction | ||||||
direction?: 'ltr' | 'rtl'; | ||||||
// focus index | ||||||
index: number; | ||||||
|
||||||
// Fill | ||||||
/** TimePicker or showTime only */ | ||||||
|
@@ -58,7 +60,7 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D | |||||
range, | ||||||
multiple, | ||||||
activeInfo = [0, 0, 0], | ||||||
|
||||||
index = 0, | ||||||
// Presets | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 避免将内部属性 index 透传到子组件/DOM 当前仍以 在本段解构保持不变的前提下,新增一个“去除 index 的转发 props”,并替换两处传参: // 紧跟解构之后添加
const forwardProps = React.useMemo(() => {
const { index: _internalIndex, ...rest } = props;
return rest as Omit<PopupProps<DateType>, 'index'>;
}, [props]); 然后将下方两处替换为: - <PopupPanel {...props} value={popupPanelValue} />
+ <PopupPanel {...forwardProps} value={popupPanelValue} />
- <Footer
- {...props}
+ <Footer
+ {...forwardProps}
showNow={multiple ? false : showNow}
invalid={disableSubmit}
onSubmit={onFooterSubmit}
/> 🤖 Prompt for AI Agents
|
||||||
presets, | ||||||
onPresetHover, | ||||||
|
@@ -80,7 +82,6 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D | |||||
onOk, | ||||||
onSubmit, | ||||||
} = props; | ||||||
|
||||||
const { prefixCls } = React.useContext(PickerContext); | ||||||
const panelPrefixCls = `${prefixCls}-panel`; | ||||||
|
||||||
|
@@ -118,7 +119,8 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D | |||||
// Arrow Offset | ||||||
const wrapperRect = wrapperRef.current.getBoundingClientRect(); | ||||||
if (!wrapperRect.height || wrapperRect.right < 0) { | ||||||
setRetryTimes((times) => Math.max(0, times - 1)); | ||||||
// Index is designed to be compatible with the bug of inconsistency between React 18 useEffect and React 19 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment mentions React 19 but the description indicates this is addressing React 18 useEffect issues. The comment should be corrected to accurately reflect that this is a workaround for React 18 useEffect behavior.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
setRetryTimes((times) => Math.max(0, times - index - 1)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 当前解释此变通方案的注释(“Index is designed to be compatible with the bug of inconsistency between React 18 useEffect and React 19”)有些模糊,并且提到了 React 19,可能会引起困惑。为了提高代码的可维护性,建议提供更详细的说明,解释为什么在 React 18 中
|
||||||
return; | ||||||
} | ||||||
|
||||||
|
@@ -138,7 +140,16 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D | |||||
setContainerOffset(0); | ||||||
} | ||||||
} | ||||||
}, [retryTimes, rtl, containerWidth, activeInputLeft, activeInputRight, selectorWidth, range]); | ||||||
}, [ | ||||||
retryTimes, | ||||||
rtl, | ||||||
containerWidth, | ||||||
activeInputLeft, | ||||||
activeInputRight, | ||||||
selectorWidth, | ||||||
range, | ||||||
index, | ||||||
]); | ||||||
|
||||||
// ======================== Custom ======================== | ||||||
function filterEmpty<T>(list: T[]) { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
将新增的 index 改为可选并标注为内部属性,避免破坏性变更
把
index
作为必选公开属性会对所有直接使用Popup
的调用方造成 TS 编译破坏。建议将其设为可选并标注内部使用,运行时仍保持解构默认值为 0,不影响现有逻辑。应用如下 diff:
📝 Committable suggestion
🤖 Prompt for AI Agents