Skip to content

Commit

Permalink
fix: no-disabled-range prop being ignored on auto-range (fixes #555)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasenkoo committed Sep 8, 2023
1 parent e092dad commit 5916ab3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/VueDatePicker/composables/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,11 @@ export const useValidation = (props: PickerBasePropsType | AllPropsType) => {

// Check if there are disabled dates for a given range
const isDateRangeAllowed = (range: Date[]): boolean => {
const datesInBetween = eachDayOfInterval({ start: range[0], end: range[1] });
return !datesInBetween.some((date) => isDisabled(date));
if (props.noDisabledRange) {
const datesInBetween = eachDayOfInterval({ start: range[0], end: range[1] });
return !datesInBetween.some((date) => isDisabled(date));
}
return true;
};

// If min or max range is set, validate given range
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/behaviour.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,25 @@ describe('It should validate various picker scenarios', () => {
expect(cell.html()).toBeTruthy();
dp.unmount();
});

it('Should enable or disable auto range selecting with no-disabled-range prop (#555)', async () => {
const today = set(new Date(), { seconds: 0, milliseconds: 0 });
const disabledDates = [addDays(today, 1), addDays(today, 2)];
const dp = await openMenu({ disabledDates, noDisabledRange: true, range: true, autoRange: 5 });

const selectAutoRange = async () => {
await dp.find(`[data-test="${resetDateTime(today)}"]`).trigger('click');
await dp.find(`[data-test="select-button"]`).trigger('click');
};

await selectAutoRange();

expect(dp.emitted()).toHaveProperty('invalid-select');

await reOpenMenu(dp, { noDisabledRange: false });

await selectAutoRange();

expect(dp.emitted()).toHaveProperty('update:model-value', [[[today, addDays(today, 5)]]]);
});
});

0 comments on commit 5916ab3

Please sign in to comment.