Skip to content

Commit b4a3dca

Browse files
committed
fix: After the RangePicker sets disabledDate, the date cannot be modified.
1 parent 281bf37 commit b4a3dca

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

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: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,25 @@ describe('Picker.Range', () => {
231231
expect(baseElement.querySelector('.rc-picker-dropdown-hidden')).toBeTruthy();
232232
});
233233

234+
it('should not be checked if the value 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+
234253
it('should close panel when finish first choose with showTime = true and disabled = [false, true]', () => {
235254
const { baseElement } = render(<DayRangePicker showTime disabled={[false, true]} />);
236255
expect(baseElement.querySelectorAll('.rc-picker-input')).toHaveLength(2);
@@ -541,7 +560,7 @@ describe('Picker.Range', () => {
541560
it('pass tabIndex', () => {
542561
const { container } = render(
543562
<div>
544-
<DayRangePicker tabIndex={-1}/>
563+
<DayRangePicker tabIndex={-1} />
545564
</div>,
546565
);
547566

@@ -705,12 +724,7 @@ describe('Picker.Range', () => {
705724
});
706725

707726
it('prefix', () => {
708-
render(
709-
<DayRangePicker
710-
prefix={<span className="prefix" />}
711-
allowClear
712-
/>,
713-
);
727+
render(<DayRangePicker prefix={<span className="prefix" />} allowClear />);
714728
expect(document.querySelector('.prefix')).toBeInTheDocument();
715729
});
716730

0 commit comments

Comments
 (0)