Skip to content

Commit

Permalink
fix: After the RangePicker sets disabledDate, the date cannot be modi…
Browse files Browse the repository at this point in the history
…fied.
  • Loading branch information
Zyf665 committed Nov 3, 2024
1 parent 281bf37 commit b4a3dca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/PickerInput/hooks/useRangeValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,9 @@ export default function useRangeValue<ValueType extends DateType[], DateType ext
// >>> Invalid
const validateDates =
// Validate start
(!start || !isInvalidateDate(start, { activeIndex: 0 })) &&
(disabled[0] || !start || !isInvalidateDate(start, { activeIndex: 0 })) &&
// Validate end
(!end || !isInvalidateDate(end, { from: start, activeIndex: 1 }));

(disabled[1] || !end || !isInvalidateDate(end, { from: start, activeIndex: 1 }));
// >>> Result
const allPassed =
// Null value is from clear button
Expand Down
28 changes: 21 additions & 7 deletions tests/range.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,25 @@ describe('Picker.Range', () => {
expect(baseElement.querySelector('.rc-picker-dropdown-hidden')).toBeTruthy();
});

it('should not be checked if the value is disabled', () => {
const onChange = jest.fn();
const { container } = render(
<DayRangePicker
disabled={[true, false]}
defaultValue={[getDay('2024-10-28'), getDay('2024-11-20')]}
disabledDate={(date: Dayjs) => date <= dayjs('2024-11-20').endOf('day')}
onChange={onChange}
/>,
);

openPicker(container, 1);
selectCell('21', 1);
expect(onChange).toHaveBeenCalledWith(
[expect.anything(), expect.anything()],
['2024-10-28', '2024-11-21'],
);
});

it('should close panel when finish first choose with showTime = true and disabled = [false, true]', () => {
const { baseElement } = render(<DayRangePicker showTime disabled={[false, true]} />);
expect(baseElement.querySelectorAll('.rc-picker-input')).toHaveLength(2);
Expand Down Expand Up @@ -541,7 +560,7 @@ describe('Picker.Range', () => {
it('pass tabIndex', () => {
const { container } = render(
<div>
<DayRangePicker tabIndex={-1}/>
<DayRangePicker tabIndex={-1} />
</div>,
);

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

it('prefix', () => {
render(
<DayRangePicker
prefix={<span className="prefix" />}
allowClear
/>,
);
render(<DayRangePicker prefix={<span className="prefix" />} allowClear />);
expect(document.querySelector('.prefix')).toBeInTheDocument();
});

Expand Down

0 comments on commit b4a3dca

Please sign in to comment.