Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: the RangePicker sets disabledDate, the date cannot be modified #888

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]}
zombieJ marked this conversation as resolved.
Show resolved Hide resolved
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