Skip to content
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

fix: Range picker rendering in wrong position #6073 #6074

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions components/vc-picker/RangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ function RangerPicker<DateType>() {
const startInputRef = ref<HTMLInputElement>(null);
const endInputRef = ref<HTMLInputElement>(null);
const arrowRef = ref<HTMLDivElement>(null);
const panelLeft = ref(0);

// ============================ Warning ============================
if (process.env.NODE_ENV !== 'production') {
Expand Down Expand Up @@ -380,6 +381,32 @@ function RangerPicker<DateType>() {
if (!mergedOpen.value && containerRef.value) {
popupMinWidth.value = containerRef.value.offsetWidth;
}
// 打开时重新计算margin距离
if (mergedOpen.value) {
setTimeout(() => {
panelLeft.value = 0;
if (
mergedActivePickerIndex.value &&
startInputDivRef.value &&
separatorRef.value &&
panelDivRef.value
) {
const arrowLeft = startInputDivRef.value.offsetWidth + separatorRef.value.offsetWidth;
if (
panelDivRef.value.offsetWidth &&
arrowRef.value.offsetWidth &&
arrowLeft >
panelDivRef.value.offsetWidth -
arrowRef.value.offsetWidth -
(props.direction === 'rtl' || arrowRef.value.offsetLeft > arrowLeft
? 0
: arrowRef.value.offsetLeft)
) {
panelLeft.value = arrowLeft;
}
}
}, 5);
}
});

// ============================ Trigger ============================
Expand Down Expand Up @@ -982,7 +1009,6 @@ function RangerPicker<DateType>() {
autocomplete = 'off',
} = props;
let arrowLeft = 0;
let panelLeft = 0;
if (
mergedActivePickerIndex.value &&
startInputDivRef.value &&
Expand All @@ -1001,8 +1027,10 @@ function RangerPicker<DateType>() {
? 0
: arrowRef.value.offsetLeft)
) {
panelLeft = arrowLeft;
panelLeft.value = arrowLeft;
}
} else {
panelLeft.value = 0;
}

const arrowPositionStyle =
Expand Down Expand Up @@ -1093,11 +1121,10 @@ function RangerPicker<DateType>() {
if (panelRender) {
mergedNodes = panelRender(mergedNodes);
}

return (
<div
class={`${prefixCls}-panel-container`}
style={{ marginLeft: `${panelLeft}px` }}
style={{ marginLeft: `${panelLeft.value}px` }}
ref={panelDivRef}
onMousedown={e => {
e.preventDefault();
Expand Down