Skip to content

Commit c787cd7

Browse files
authored
Merge 541cef7 into 6919d7e
2 parents 6919d7e + 541cef7 commit c787cd7

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

docs/examples/range.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ export default () => {
5050
<div>
5151
<h2>Value: {value ? `${formatDate(value[0])} ~ ${formatDate(value[1])}` : 'null'}</h2>
5252

53-
<div style={{ display: 'flex', flexWrap: 'wrap' }}>
53+
<div style={{ display: 'flex', flexWrap: 'wrap', width: '100%' }}>
5454
<div style={{ margin: '0 8px' }}>
5555
<h3>Basic</h3>
5656
<RangePicker<Moment>
5757
{...sharedProps}
58+
style={{width: '100%'}}
5859
value={undefined}
5960
locale={zhCN}
6061
allowClear

src/RangePicker.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,11 +892,16 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
892892
const panelWidth = panelDivRef.current.offsetWidth;
893893
const arrowWidth = arrowRef.current.offsetWidth;
894894

895+
const inputAreaWidth = startInputDivRef.current.offsetWidth * 2 + separatorRef.current.offsetWidth;
896+
895897
if (
896898
panelWidth &&
897899
arrowWidth &&
898-
arrowLeft > panelWidth - arrowWidth - (direction === 'rtl' ? 0 : arrowMarginLeft)
900+
arrowLeft > panelWidth - arrowWidth - (direction === 'rtl' ? 0 : arrowMarginLeft) &&
901+
// If input size is too small that panel cannot move to right, let it keep left.
902+
inputAreaWidth >= 2 * panelWidth
899903
) {
904+
900905
panelLeft = arrowLeft;
901906
}
902907
}

tests/range.spec.tsx

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,7 @@ describe('Picker.Range', () => {
18071807
} else if (this.className.includes('panel-container')) {
18081808
return 311;
18091809
} else if (this.className.includes('input')) {
1810-
return 285;
1810+
return 306;
18111811
} else if (this.className.includes('range-separator')) {
18121812
return 10;
18131813
}
@@ -1831,7 +1831,7 @@ describe('Picker.Range', () => {
18311831
);
18321832
openPicker(container, 1);
18331833
expect(document.querySelector('.rc-picker-panel-container')).toHaveStyle({
1834-
marginLeft: '295px',
1834+
marginLeft: '316px',
18351835
});
18361836
mock.mockRestore();
18371837
});
@@ -1927,4 +1927,42 @@ describe('Picker.Range', () => {
19271927
fireEvent.click(document.querySelector('.rc-picker-cell'));
19281928
expect(document.querySelectorAll('.rc-picker-input')[1]).toHaveClass('rc-picker-input-active');
19291929
});
1930+
1931+
it('If input size is too small that panel cannot move to right, let it keep left', () => {
1932+
const mock = spyElementPrototypes(HTMLElement, {
1933+
offsetWidth: {
1934+
get() {
1935+
if (this.className.includes('range-arrow')) {
1936+
return 14;
1937+
} else if (this.className.includes('panel-container')) {
1938+
return 311;
1939+
} else if (this.className.includes('input')) {
1940+
return 100;
1941+
} else if (this.className.includes('range-separator')) {
1942+
return 10;
1943+
}
1944+
},
1945+
},
1946+
offsetLeft: {
1947+
get() {
1948+
if (this.className.includes('range-arrow')) {
1949+
return 305;
1950+
}
1951+
},
1952+
},
1953+
});
1954+
const { container } = render(
1955+
<MomentRangePicker
1956+
allowClear
1957+
defaultValue={[moment('1990-09-03'), moment('1989-11-28')]}
1958+
clearIcon={<span>X</span>}
1959+
suffixIcon={<span>O</span>}
1960+
/>,
1961+
);
1962+
openPicker(container, 1);
1963+
expect(document.querySelector('.rc-picker-panel-container')).toHaveStyle({
1964+
marginLeft: '0px',
1965+
});
1966+
mock.mockRestore();
1967+
});
19301968
});

0 commit comments

Comments
 (0)