Skip to content

Commit 19f787f

Browse files
author
huan.yang
committed
fix: placement right
1 parent 4f9a6a5 commit 19f787f

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

assets/index.less

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@
109109
border: none;
110110
outline: none;
111111
cursor: pointer;
112-
transition: background 0.3s, border 0.3s;
112+
transition:
113+
background 0.3s,
114+
border 0.3s;
113115

114116
&:hover {
115117
background: fade(blue, 30%);
@@ -440,7 +442,7 @@
440442
}
441443
}
442444
&-placement-bottomLeft,
443-
&-placement-bottomright {
445+
&-placement-bottomRight {
444446
.@{prefix-cls}-range-arrow {
445447
top: (@arrow-size / 2 + 1px);
446448
transform: rotate(-45deg);
@@ -449,11 +451,9 @@
449451

450452
.@{prefix-cls}-range-arrow {
451453
position: absolute;
452-
left: @arrow-size;
453454
z-index: 1;
454455
width: @arrow-size;
455456
height: @arrow-size;
456-
margin-left: 10px;
457457
transition: all 0.3s;
458458

459459
.@{prefix-cls}-dropdown-rtl& {

src/PickerInput/Popup/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface PopupProps<DateType extends object = any, PresetValue = DateTyp
2121

2222
// Range
2323
activeOffset?: number;
24-
24+
placement?: string;
2525
// Direction
2626
direction?: 'ltr' | 'rtl';
2727

@@ -46,6 +46,7 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D
4646
range,
4747
multiple,
4848
activeOffset = 0,
49+
placement,
4950

5051
// Presets
5152
presets,
@@ -196,6 +197,7 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D
196197
);
197198

198199
if (range) {
200+
const placementRight = placement?.toLowerCase().includes('right');
199201
renderNode = (
200202
<div
201203
ref={wrapperRef}
@@ -204,7 +206,7 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D
204206
<div
205207
ref={arrowRef}
206208
className={`${prefixCls}-range-arrow`}
207-
style={{ [rtl ? 'right' : 'left']: activeOffset }}
209+
style={{ [rtl || placementRight ? 'right' : 'left']: activeOffset }}
208210
/>
209211

210212
{/* Watch for container size */}

src/PickerInput/RangePicker.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ function RangePicker<DateType extends object = any>(
157157
prefixCls,
158158
styles,
159159
classNames,
160+
placement,
160161

161162
// Value
162163
defaultValue,
@@ -554,6 +555,7 @@ function RangePicker<DateType extends object = any>(
554555
range
555556
multiplePanel={multiplePanel}
556557
activeOffset={activeOffset}
558+
placement={placement}
557559
// Disabled
558560
disabledDate={mergedDisabledDate}
559561
// Focus

src/PickerInput/Selector/RangeSelector.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface RangeSelectorProps<DateType = any> extends SelectorProps<DateTy
3535

3636
// Invalid
3737
invalid: [boolean, boolean];
38-
38+
placement?: string;
3939
// Offset
4040
/**
4141
* Trigger when the active bar offset position changed.
@@ -101,6 +101,7 @@ function RangeSelector<DateType extends object = any>(
101101

102102
// Offset
103103
onActiveOffset,
104+
placement,
104105

105106
// Native
106107
onMouseDown,
@@ -181,10 +182,9 @@ function RangeSelector<DateType extends object = any>(
181182
const input = getInput(activeIndex);
182183
if (input) {
183184
const { offsetWidth, offsetLeft, offsetParent } = input.nativeElement;
184-
185185
let offset = offsetLeft;
186+
const parentElement = offsetParent as HTMLElement;
186187
if (rtl) {
187-
const parentElement = offsetParent as HTMLElement;
188188
const parentStyle = getComputedStyle(parentElement);
189189

190190
offset =
@@ -200,8 +200,16 @@ function RangeSelector<DateType extends object = any>(
200200
width: offsetWidth,
201201
[offsetUnit]: offset,
202202
}));
203-
204-
onActiveOffset(activeIndex === 0 ? 0 : offset);
203+
const rightMode = placement?.toLowerCase()?.includes('right');
204+
onActiveOffset(
205+
activeIndex === 0
206+
? rightMode
207+
? parentElement.offsetWidth - 20
208+
: 0
209+
: rightMode
210+
? offsetWidth - 20
211+
: offset,
212+
);
205213
}
206214
});
207215

0 commit comments

Comments
 (0)