Skip to content

Commit f6ee130

Browse files
committed
Merge branch 'master' into fix/range-picker-arrow-wrong-position
2 parents 8f0cdc4 + e1d6848 commit f6ee130

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-picker",
3-
"version": "4.7.0",
3+
"version": "4.7.2",
44
"description": "React date & time picker",
55
"keywords": [
66
"react",

src/PickerInput/Selector/RangeSelector.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ function RangeSelector<DateType extends object = any>(
200200
const offsetLeft = x - pX;
201201

202202
const activeOffset = placementRight ? parentWidth - inputWidth - offsetLeft : offsetLeft;
203-
setActiveBarStyle(({ position }) => ({
204-
position,
203+
setActiveBarStyle(({ insetInlineStart, insetInlineEnd, ...rest }) => ({
204+
...rest,
205205
width: inputWidth,
206206
// parent will have border while focus, so need to cut `parentBorderWidth` on opposite side.
207207
[offsetUnit]: activeOffset - parentBorderRightWidth,

src/PickerInput/hooks/useRangeValue.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,9 @@ export default function useRangeValue<ValueType extends DateType[], DateType ext
270270
// >>> Invalid
271271
const validateDates =
272272
// Validate start
273-
(!start || !isInvalidateDate(start, { activeIndex: 0 })) &&
273+
(disabled[0] || !start || !isInvalidateDate(start, { activeIndex: 0 })) &&
274274
// Validate end
275-
(!end || !isInvalidateDate(end, { from: start, activeIndex: 1 }));
276-
275+
(disabled[1] || !end || !isInvalidateDate(end, { from: start, activeIndex: 1 }));
277276
// >>> Result
278277
const allPassed =
279278
// Null value is from clear button

tests/range.spec.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,43 @@ describe('Picker.Range', () => {
231231
expect(baseElement.querySelector('.rc-picker-dropdown-hidden')).toBeTruthy();
232232
});
233233

234+
it('should not be checked if the startDate is disabled', () => {
235+
const onChange = jest.fn();
236+
const { container } = render(
237+
<DayRangePicker
238+
disabled={[true, false]}
239+
defaultValue={[getDay('2024-10-28'), getDay('2024-11-20')]}
240+
disabledDate={(date: Dayjs) => date <= dayjs('2024-11-20').endOf('day')}
241+
onChange={onChange}
242+
/>,
243+
);
244+
245+
openPicker(container, 1);
246+
selectCell('21', 1);
247+
expect(onChange).toHaveBeenCalledWith(
248+
[expect.anything(), expect.anything()],
249+
['2024-10-28', '2024-11-21'],
250+
);
251+
});
252+
it('should not be checked if the endDate is disabled', () => {
253+
const onChange = jest.fn();
254+
const { container } = render(
255+
<DayRangePicker
256+
disabled={[false, true]}
257+
defaultValue={[getDay('2024-10-28'), getDay('2024-11-20')]}
258+
disabledDate={(date: Dayjs) => date >= dayjs('2024-11-10').endOf('day')}
259+
onChange={onChange}
260+
/>,
261+
);
262+
263+
openPicker(container, 0);
264+
selectCell('21', 0);
265+
expect(onChange).toHaveBeenCalledWith(
266+
[expect.anything(), expect.anything()],
267+
['2024-10-21', '2024-11-20'],
268+
);
269+
});
270+
234271
it('should close panel when finish first choose with showTime = true and disabled = [false, true]', () => {
235272
const { baseElement } = render(<DayRangePicker showTime disabled={[false, true]} />);
236273
expect(baseElement.querySelectorAll('.rc-picker-input')).toHaveLength(2);

0 commit comments

Comments
 (0)