DatePicker: fix week selection range highlight (#10712)

pull/10716/head
Jiewei Qian 2018-04-15 16:30:14 +10:00 committed by 杨奕
parent 39bb82f462
commit 7c3cadba5c
3 changed files with 47 additions and 1 deletions

View File

@ -311,7 +311,8 @@
newDate.setDate(parseInt(cell.text, 10));
return getWeekNumber(newDate) === getWeekNumber(this.date);
const valueYear = isDate(this.value) ? this.value.getFullYear() : null;
return year === valueYear && getWeekNumber(newDate) === getWeekNumber(this.value);
},
markRange(maxDate) {

View File

@ -95,6 +95,7 @@ export const getStartDateOfMonth = function(year, month) {
};
export const getWeekNumber = function(src) {
if (!isDate(src)) return null;
const date = new Date(src.getTime());
date.setHours(0, 0, 0, 0);
// Thursday in current week decides the year.

View File

@ -1354,6 +1354,50 @@ describe('DatePicker', () => {
}, DELAY);
}, DELAY);
});
it('highlight correctly', done => {
vm = createVue({
template: '<el-date-picker type="week" v-model="value" ref="compo" />',
data() {
return {
value: null
};
}
}, true);
const input = vm.$el.querySelector('input');
input.blur();
input.focus();
setTimeout(() => {
const pickerEl = vm.$refs.compo.picker.$el;
const numberOfHighlightRows = () => pickerEl.querySelectorAll('.el-date-table__row.current').length;
expect(numberOfHighlightRows()).to.equal(0);
setTimeout(() => {
pickerEl.querySelector('td.available').click();
setTimeout(() => {
expect(vm.value).to.exist;
input.blur();
input.focus();
setTimeout(() => {
expect(numberOfHighlightRows()).to.equal(1);
// test: next month should not have highlight
pickerEl.querySelector('.el-icon-arrow-right').click();
setTimeout(() => {
expect(numberOfHighlightRows()).to.equal(0);
// test: next year should not have highlight
pickerEl.querySelector('.el-icon-arrow-left').click(); // go back one month
pickerEl.querySelector('.el-icon-d-arrow-right').click();
setTimeout(() => {
expect(numberOfHighlightRows()).to.equal(0);
done();
}, DELAY);
}, DELAY);
}, DELAY);
}, DELAY);
}, DELAY);
}, DELAY);
});
});
describe('type:daterange', () => {