Skip to content

Commit b7cd8d6

Browse files
authored
fix: arrow position when placement is right again (#823)
1 parent 53396ca commit b7cd8d6

File tree

3 files changed

+11
-23
lines changed

3 files changed

+11
-23
lines changed

docs/examples/range.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export default () => {
3737
value,
3838
onChange,
3939
onCalendarChange,
40+
placement: 'topRight',
4041
};
4142

4243
const rangePickerRef = React.useRef<PickerRef>(null);

src/PickerInput/Selector/RangeSelector.tsx

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function RangeSelector<DateType extends object = any>(
170170
});
171171

172172
// ====================== ActiveBar =======================
173-
const offsetUnit = rtl ? 'right' : 'left';
173+
const offsetUnit = rtl ? 'insetInlineEnd' : 'insetInlineStart';
174174

175175
const [activeBarStyle, setActiveBarStyle] = React.useState<React.CSSProperties>({
176176
position: 'absolute',
@@ -182,27 +182,14 @@ function RangeSelector<DateType extends object = any>(
182182
const input = getInput(activeIndex);
183183
if (input) {
184184
const { offsetWidth, offsetLeft, offsetParent } = input.nativeElement;
185-
let offset = offsetLeft;
186-
const parentElement = offsetParent as HTMLElement;
187-
if (rtl) {
188-
const parentStyle = getComputedStyle(parentElement);
189-
190-
offset =
191-
parentElement.offsetWidth -
192-
parseFloat(parentStyle.borderRightWidth) -
193-
parseFloat(parentStyle.borderLeftWidth) -
194-
offsetLeft -
195-
offsetWidth;
196-
}
197-
185+
const parentWidth = (offsetParent as HTMLElement)?.offsetWidth || 0;
198186
setActiveBarStyle((ori) => ({
199187
...ori,
200188
width: offsetWidth,
201-
[offsetUnit]: offset,
189+
[offsetUnit]: offsetLeft,
202190
}));
203191
const placementRight = placement?.toLowerCase().endsWith('right');
204-
const startOffset = placementRight ? parentElement?.offsetWidth : 0;
205-
onActiveOffset(activeIndex === 0 ? startOffset : offset);
192+
onActiveOffset(placementRight ? (parentWidth - offsetWidth - offsetLeft) : offsetLeft);
206193
}
207194
});
208195

tests/__snapshots__/range.spec.tsx.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ exports[`Picker.Range icon 1`] = `
3434
</div>
3535
<div
3636
class="rc-picker-active-bar"
37-
style="position: absolute; width: 0px; left: 0px;"
37+
style="position: absolute; width: 0px; inset-inline-start: 0;"
3838
/>
3939
<span
4040
class="rc-picker-suffix"
@@ -89,7 +89,7 @@ exports[`Picker.Range onPanelChange is array args should render correctly in pla
8989
</div>
9090
<div
9191
class="rc-picker-active-bar"
92-
style="position: absolute; width: 0px; left: 0px;"
92+
style="position: absolute; width: 0px; inset-inline-start: 0;"
9393
/>
9494
</div>
9595
</div>
@@ -129,7 +129,7 @@ exports[`Picker.Range onPanelChange is array args should render correctly in rtl
129129
</div>
130130
<div
131131
class="rc-picker-active-bar"
132-
style="position: absolute; width: 0px; right: 0px;"
132+
style="position: absolute; width: 0px; inset-inline-end: 0;"
133133
/>
134134
</div>
135135
</div>
@@ -170,7 +170,7 @@ exports[`Picker.Range panelRender 1`] = `
170170
</div>
171171
<div
172172
class="rc-picker-active-bar"
173-
style="position: absolute; width: 0px; left: 0px;"
173+
style="position: absolute; width: 0px; inset-inline-start: 0;"
174174
/>
175175
</div>
176176
</div>
@@ -236,7 +236,7 @@ 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: 0px; inset-inline-start: 0;"
240240
/>
241241
</div>
242242
</div>
@@ -1293,7 +1293,7 @@ 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: 0px; inset-inline-start: 0;"
12971297
/>
12981298
</div>
12991299
</div>

0 commit comments

Comments
 (0)