fix(Calendar): auto selected to max range when show-confirm is false (#9948)

* fix(Calendar): auto selected to max range when show-confirm is false

* test: update
This commit is contained in:
neverland 2021-11-27 15:19:35 +08:00 committed by GitHub
parent 94e00d443f
commit 013991b1e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 40 deletions

View File

@ -344,15 +344,11 @@ export default defineComponent({
const valid = checkRange(date as [Date, Date]); const valid = checkRange(date as [Date, Date]);
if (!valid) { if (!valid) {
// auto selected to max range if showConfirm // auto selected to max range
if (props.showConfirm) { setCurrentDate([
setCurrentDate([ (date as Date[])[0],
(date as Date[])[0], getDayByOffset((date as Date[])[0], +props.maxRange - 1),
getDayByOffset((date as Date[])[0], +props.maxRange - 1), ]);
]);
} else {
setCurrentDate(date);
}
return; return;
} }
} }

View File

@ -2,36 +2,7 @@ import { Calendar } from '..';
import { mount, later } from '../../../test'; import { mount, later } from '../../../test';
import { minDate, maxDate } from './utils'; import { minDate, maxDate } from './utils';
test('max-range prop when type is range and showConfirm is false', async () => { test('should limit max range when using max-range prop and type is range', async () => {
const wrapper = mount(Calendar, {
props: {
type: 'range',
minDate,
maxDate,
maxRange: 3,
poppable: false,
showConfirm: false,
lazyRender: false,
},
});
await later();
const days = wrapper.findAll('.van-calendar__day');
days[12].trigger('click');
days[18].trigger('click');
expect(wrapper.emitted<[Date]>('select')![0][0]).toEqual([
new Date(2010, 0, 13),
]);
expect(wrapper.emitted<[Date]>('select')![1][0]).toEqual([
new Date(2010, 0, 13),
new Date(2010, 0, 19),
]);
expect(wrapper.emitted('confirm')).toBeFalsy();
});
test('max-range prop when type is range and showConfirm is true', async () => {
const wrapper = mount(Calendar, { const wrapper = mount(Calendar, {
props: { props: {
type: 'range', type: 'range',
@ -59,7 +30,7 @@ test('max-range prop when type is range and showConfirm is true', async () => {
expect(wrapper.emitted('confirm')).toBeFalsy(); expect(wrapper.emitted('confirm')).toBeFalsy();
}); });
test('max-range prop when type is multiple', async () => { test('should limit max range when using max-range prop and type is multiple', async () => {
const wrapper = mount(Calendar, { const wrapper = mount(Calendar, {
props: { props: {
type: 'multiple', type: 'multiple',