Skip to content

Commit c012bfd

Browse files
authored
fix: arrow position retry (#909)
* fix: arrow position retry * test: update snapshot
1 parent 23ff742 commit c012bfd

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/PickerInput/Popup/index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D
102102
};
103103

104104
const [activeInputLeft, activeInputRight, selectorWidth] = activeInfo;
105+
const [retryTimes, setRetryTimes] = React.useState(0);
106+
107+
React.useEffect(() => {
108+
setRetryTimes(10);
109+
}, [activeInputLeft]);
105110

106111
React.useEffect(() => {
107112
// `activeOffset` is always align with the active input element
@@ -112,6 +117,11 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D
112117

113118
// Arrow Offset
114119
const wrapperRect = wrapperRef.current.getBoundingClientRect();
120+
if (!wrapperRect.height || wrapperRect.right < 0) {
121+
setRetryTimes((times) => Math.max(0, times - 1));
122+
return;
123+
}
124+
115125
const nextArrowOffset =
116126
(rtl ? activeInputRight - arrowWidth : activeInputLeft) - wrapperRect.left;
117127
setArrowOffset(nextArrowOffset);
@@ -128,7 +138,7 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D
128138
setContainerOffset(0);
129139
}
130140
}
131-
}, [rtl, containerWidth, activeInputLeft, activeInputRight, selectorWidth, range]);
141+
}, [retryTimes, rtl, containerWidth, activeInputLeft, activeInputRight, selectorWidth, range]);
132142

133143
// ======================== Custom ========================
134144
function filterEmpty<T>(list: T[]) {

tests/range.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,7 @@ describe('Picker.Range', () => {
18321832
width,
18331833
left,
18341834
right: left + width,
1835+
height: 1,
18351836
};
18361837
},
18371838
offsetWidth: {

0 commit comments

Comments
 (0)