Skip to content

Commit

Permalink
DatePicker: panels should display different months (ElemeFE#9471)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hi-Linlin authored and Leopoldthecoder committed Jan 28, 2018
1 parent 3d7d498 commit e40c17f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/date-picker/src/panel/date-range.vue
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,17 @@
// should allow them to be set individually in the future
if (this.minDate) {
this.leftDate = this.minDate;
this.rightDate = this.unlinkPanels && this.maxDate
? this.maxDate
: nextMonth(this.leftDate);
if (this.unlinkPanels && this.maxDate) {
const minDateYear = this.minDate.getFullYear();
const minDateMonth = this.minDate.getMonth();
const maxDateYear = this.maxDate.getFullYear();
const maxDateMonth = this.maxDate.getMonth();
this.rightDate = minDateYear === maxDateYear && minDateMonth === maxDateMonth
? nextMonth(this.maxDate)
: this.maxDate;
} else {
this.rightDate = nextMonth(this.leftDate);
}
} else {
this.leftDate = calcDefaultValue(this.defaultValue)[0];
this.rightDate = nextMonth(this.leftDate);
Expand Down
26 changes: 26 additions & 0 deletions test/unit/specs/date-picker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,32 @@ describe('DatePicker', () => {
}, DELAY);
});

it('type:daterange unlink:true', done => {
vm = createVue({
template: '<el-date-picker type="daterange" unlink-panels v-model="value" ref="compo" />',
data() {
return {
value: [new Date(2000, 9, 1), new Date(2000, 9, 2)]
};
}
}, true);

const rangePicker = vm.$refs.compo;
const inputs = rangePicker.$el.querySelectorAll('input');
setTimeout(_ => {
inputs[0].focus();
setTimeout(_ => {
const panels = rangePicker.picker.$el.querySelectorAll('.el-date-range-picker__content');
const left = panels[0].querySelector('.el-date-range-picker__header');
const right = panels[1].querySelector('.is-right .el-date-range-picker__header');
const leftText = left.textContent.match(/\d+/g).map(i => Number(i));
const rightText = right.textContent.match(/\d+/g).map(i => Number(i));
expect(rightText[1] - leftText[1]).to.equal(1); // one month
done();
}, DELAY);
}, DELAY);
});

it('unlink panels', done => {
vm = createTest(DatePicker, {
type: 'daterange',
Expand Down

0 comments on commit e40c17f

Please sign in to comment.