Skip to content

Commit 79ec125

Browse files
committed
fix: arrow position retry
1 parent 23ff742 commit 79ec125

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
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/__snapshots__/range.spec.tsx.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,14 @@ exports[`Picker.Range use dateRender and monthCellRender in date range picker 1`
236236
</div>
237237
<div
238238
class="rc-picker-active-bar"
239-
style="position: absolute; width: 0px; left: 0px;"
239+
style="position: absolute; width: 100px; left: 100px;"
240240
/>
241241
</div>
242242
</div>
243243
<div>
244244
<div
245245
class="rc-picker-dropdown rc-picker-dropdown-range rc-picker-dropdown-placement-bottomLeft"
246-
style="--arrow-x: 0px; --arrow-y: 0px; left: -1000vw; top: -1000vh; box-sizing: border-box;"
246+
style="--arrow-x: 0px; --arrow-y: 0px; left: -1000vw; top: -1000vh; box-sizing: border-box; min-width: 200px;"
247247
>
248248
<div
249249
class="rc-picker-range-wrapper rc-picker-date-range-wrapper"
@@ -1293,14 +1293,14 @@ exports[`Picker.Range use dateRender and monthCellRender in month range picker 1
12931293
</div>
12941294
<div
12951295
class="rc-picker-active-bar"
1296-
style="position: absolute; width: 0px; left: 0px;"
1296+
style="position: absolute; width: 100px; left: 100px;"
12971297
/>
12981298
</div>
12991299
</div>
13001300
<div>
13011301
<div
13021302
class="rc-picker-dropdown rc-picker-dropdown-range rc-picker-dropdown-placement-bottomLeft"
1303-
style="--arrow-x: 0px; --arrow-y: 0px; left: -1000vw; top: -1000vh; box-sizing: border-box;"
1303+
style="--arrow-x: 0px; --arrow-y: 0px; left: -1000vw; top: -1000vh; box-sizing: border-box; min-width: 200px;"
13041304
>
13051305
<div
13061306
class="rc-picker-range-wrapper rc-picker-month-range-wrapper"

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)