Skip to content

Commit 277bf75

Browse files
authored
fix: Arrow logic adjust (#753)
* fix: arrow offset * chore: fix offset logic
1 parent e43d866 commit 277bf75

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

docs/examples/debug.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,10 @@ export default () => {
146146

147147
return (
148148
<div>
149+
<RangePicker {...sharedLocale} open picker="time" style={{ width: 400 }} />
150+
149151
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 16 }}>
150-
<PickerPanel
152+
{/* <PickerPanel
151153
generateConfig={dayjsGenerateConfig}
152154
locale={zhCN}
153155
value={value}
@@ -156,7 +158,7 @@ export default () => {
156158
console.error('1');
157159
console.log('🎲 PanelValue Change:', panelValue, mode);
158160
}}
159-
/>
161+
/> */}
160162
</div>
161163
</div>
162164
);

src/PickerInput/Popup/index.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D
7474
const rtl = direction === 'rtl';
7575

7676
// ========================= Refs =========================
77+
const arrowRef = React.useRef<HTMLDivElement>(null);
7778
const wrapperRef = React.useRef<HTMLDivElement>(null);
7879

7980
// ======================== Offset ========================
@@ -90,10 +91,14 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D
9091
// `activeOffset` is always align with the active input element
9192
// So we need only check container contains the `activeOffset`
9293
if (range) {
93-
if (activeOffset + containerWidth < wrapperRef.current?.offsetWidth) {
94-
setContainerOffset(activeOffset);
95-
} else {
94+
// Offset in case container has border radius
95+
const arrowWidth = arrowRef.current?.offsetWidth || 0;
96+
97+
const maxOffset = containerWidth - arrowWidth;
98+
if (activeOffset <= maxOffset) {
9699
setContainerOffset(0);
100+
} else {
101+
setContainerOffset(activeOffset + arrowWidth - containerWidth);
97102
}
98103
}
99104
}, [containerWidth, activeOffset, range]);
@@ -197,6 +202,7 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D
197202
className={classNames(`${prefixCls}-range-wrapper`, `${prefixCls}-${picker}-range-wrapper`)}
198203
>
199204
<div
205+
ref={arrowRef}
200206
className={`${prefixCls}-range-arrow`}
201207
style={{ [rtl ? 'right' : 'left']: activeOffset }}
202208
/>

src/PickerInput/Selector/RangeSelector.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ function RangeSelector<DateType extends object = any>(
174174

175175
const syncActiveOffset = useEvent(() => {
176176
const input = getInput(activeIndex);
177-
if (input) {
177+
if (activeIndex === 0) {
178+
onActiveOffset(0);
179+
} else if (input) {
178180
const { offsetWidth, offsetLeft, offsetParent } = input.nativeElement;
179181

180182
let offset = offsetLeft;

tests/range.spec.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,7 +1659,7 @@ describe('Picker.Range', () => {
16591659
offsetWidth: {
16601660
get() {
16611661
if (this.className.includes('range-arrow')) {
1662-
return 14;
1662+
return 0;
16631663
} else if (this.className.includes('panel-container')) {
16641664
return 312;
16651665
} else if (this.className.includes('input')) {
@@ -1695,7 +1695,7 @@ describe('Picker.Range', () => {
16951695
offsetWidth: {
16961696
get() {
16971697
if (this.className.includes('range-arrow')) {
1698-
return 14;
1698+
return 0;
16991699
} else if (this.className.includes('panel-container')) {
17001700
return 312;
17011701
} else if (this.className.includes('input')) {
@@ -1722,6 +1722,7 @@ describe('Picker.Range', () => {
17221722
/>,
17231723
);
17241724
openPicker(container, 1);
1725+
console.log(document.querySelector<HTMLElement>('.rc-picker-panel-container').style.cssText);
17251726
expect(document.querySelector('.rc-picker-panel-container')).toHaveStyle({ marginLeft: 0 });
17261727
mock.mockRestore();
17271728
});

0 commit comments

Comments
 (0)