-
-
Notifications
You must be signed in to change notification settings - Fork 334
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 | ||||||
|
||||||
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 | ||||||
|
// Index is designed to be compatible with the bug of inconsistency between React 18 useEffect and React 19 | |
// Index is designed to be compatible with the bug of inconsistency in React 18 useEffect behavior |
Copilot uses AI. Check for mistakes.
Outdated
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 is designed to be compatible with the bug of inconsistency between React 18 useEffect and React 19”)有些模糊,并且提到了 React 19,可能会引起困惑。为了提高代码的可维护性,建议提供更详细的说明,解释为什么在 React 18 中 useEffect
的行为不一致,以及为何减去 index
可以解决这个问题。这将帮助未来的开发者更好地理解这段代码的意图。
// 这是一个绕过 React 18 中 useEffect 行为不一致问题的变通方案。
// 在某些情况下(例如切换输入框后),此 useEffect 在 React 18 中可能会比在 React 17 中多执行一次,
// 导致在布局稳定前重试次数就已耗尽。
// 通过减去当前激活的输入框索引 `index` (0 或 1) 来补偿这次额外的执行,
// 确保定位逻辑有足够的时间在 `wrapperRef` 可用后执行。
// 关联 issue: https://github.com/ant-design/ant-design/issues/54885
setRetryTimes((times) => Math.max(0, times - index - 1));
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