Skip to content

Commit c3b4f7e

Browse files
elevenskyhuan.yangafc163
authored
fix: placement right (#771)
* fix: placement right * test: add palcement right * Update index.less * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review --------- Co-authored-by: huan.yang <[email protected]> Co-authored-by: afc163 <[email protected]>
1 parent 4c1d4cd commit c3b4f7e

File tree

6 files changed

+68
-12
lines changed

6 files changed

+68
-12
lines changed

assets/index.less

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,12 @@
437437
&-placement-topLeft,
438438
&-placement-topRight {
439439
.@{prefix-cls}-range-arrow {
440-
bottom: @arrow-size / 2 + 1px;
440+
bottom: (@arrow-size / 2 + 1px);
441441
transform: rotate(135deg);
442442
}
443443
}
444444
&-placement-bottomLeft,
445-
&-placement-bottomright {
445+
&-placement-bottomRight {
446446
.@{prefix-cls}-range-arrow {
447447
top: (@arrow-size / 2 + 1px);
448448
transform: rotate(-45deg);
@@ -451,11 +451,9 @@
451451

452452
.@{prefix-cls}-range-arrow {
453453
position: absolute;
454-
left: @arrow-size;
455454
z-index: 1;
456455
width: @arrow-size;
457456
height: @arrow-size;
458-
margin-left: 10px;
459457
transition: all 0.3s;
460458

461459
.@{prefix-cls}-dropdown-rtl& {
@@ -490,7 +488,7 @@
490488
&::after {
491489
width: @arrow-size - 2px;
492490
height: @arrow-size - 2px;
493-
border: (@arrow-size - 2px) / 2 solid blue;
491+
border: ((@arrow-size - 2px) / 2) solid blue;
494492
border-color: @background-color @background-color transparent transparent;
495493
}
496494
}

src/PickerInput/Popup/index.tsx

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

3333
// Range
3434
activeOffset?: number;
35-
35+
placement?: string;
3636
// Direction
3737
direction?: 'ltr' | 'rtl';
3838

@@ -57,6 +57,7 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D
5757
range,
5858
multiple,
5959
activeOffset = 0,
60+
placement,
6061

6162
// Presets
6263
presets,
@@ -207,6 +208,7 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D
207208
);
208209

209210
if (range) {
211+
const placementRight = placement?.toLowerCase().endsWith('right');
210212
renderNode = (
211213
<div
212214
ref={wrapperRef}
@@ -215,7 +217,7 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D
215217
<div
216218
ref={arrowRef}
217219
className={`${prefixCls}-range-arrow`}
218-
style={{ [rtl ? 'right' : 'left']: activeOffset }}
220+
style={{ [rtl || placementRight ? 'right' : 'left']: activeOffset }}
219221
/>
220222

221223
{/* Watch for container size */}

src/PickerInput/RangePicker.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ function RangePicker<DateType extends object = any>(
160160
prefixCls,
161161
styles,
162162
classNames,
163+
placement,
163164

164165
// Value
165166
defaultValue,
@@ -564,6 +565,7 @@ function RangePicker<DateType extends object = any>(
564565
range
565566
multiplePanel={multiplePanel}
566567
activeOffset={activeOffset}
568+
placement={placement}
567569
// Disabled
568570
disabledDate={mergedDisabledDate}
569571
// Focus

src/PickerInput/Selector/RangeSelector.tsx

Lines changed: 11 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,14 @@ function RangeSelector<DateType extends object = any>(
200200
width: offsetWidth,
201201
[offsetUnit]: offset,
202202
}));
203-
204-
onActiveOffset(activeIndex === 0 ? 0 : offset);
203+
const placementRight = placement?.toLowerCase().endsWith('right');
204+
const startOffset = placementRight
205+
? parentElement?.offsetWidth - 20
206+
: 0;
207+
const endOffset = placementRight
208+
? offsetWidth - 20
209+
: offset;
210+
onActiveOffset(activeIndex === 0 ? startOffset : endOffset);
205211
}
206212
});
207213

tests/__snapshots__/range.spec.tsx.snap

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,46 @@ exports[`Picker.Range icon 1`] = `
5555
</div>
5656
`;
5757

58+
exports[`Picker.Range onPanelChange is array args should render correctly in placement right 1`] = `
59+
<div>
60+
<div
61+
class="rc-picker rc-picker-range rc-picker-focused"
62+
>
63+
<div
64+
class="rc-picker-input rc-picker-input-active"
65+
>
66+
<input
67+
aria-invalid="false"
68+
autocomplete="off"
69+
date-range="start"
70+
size="12"
71+
value=""
72+
/>
73+
</div>
74+
<div
75+
class="rc-picker-range-separator"
76+
>
77+
~
78+
</div>
79+
<div
80+
class="rc-picker-input"
81+
>
82+
<input
83+
aria-invalid="false"
84+
autocomplete="off"
85+
date-range="end"
86+
size="12"
87+
value=""
88+
/>
89+
</div>
90+
<div
91+
class="rc-picker-active-bar"
92+
style="position: absolute; width: 0px; left: 0px;"
93+
/>
94+
</div>
95+
</div>
96+
`;
97+
5898
exports[`Picker.Range onPanelChange is array args should render correctly in rtl 1`] = `
5999
<div>
60100
<div

tests/range.spec.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,14 @@ describe('Picker.Range', () => {
603603
const { container } = render(<DayRangePicker direction="rtl" />);
604604
expect(container).toMatchSnapshot();
605605
});
606+
607+
it('should render correctly in placement right', () => {
608+
const { container } = render(<DayRangePicker placement="bottomRight" />);
609+
openPicker(container);
610+
611+
expect(container).toMatchSnapshot();
612+
expect(document.querySelector('.rc-picker-dropdown-placement-bottomRight')).toBeTruthy();
613+
});
606614
});
607615

608616
it('type can not change before start time', () => {

0 commit comments

Comments
 (0)