Reset panel selectionMode and positioning on blur

This commit is contained in:
Sergio Crisostomo 2018-01-24 10:55:42 +01:00
parent 15457562ea
commit c2b7fed05f
3 changed files with 21 additions and 10 deletions

View file

@ -185,26 +185,31 @@
const minDate = newVal[0] ? toDate(newVal[0]) : null; const minDate = newVal[0] ? toDate(newVal[0]) : null;
const maxDate = newVal[1] ? toDate(newVal[1]) : null; const maxDate = newVal[1] ? toDate(newVal[1]) : null;
this.dates = [minDate, maxDate].sort(); this.dates = [minDate, maxDate].sort();
if (JSON.stringify(this.dates) === '[null,null]') {
const leftPanelDate = this.startDate || new Date();
this.leftPanelDate = leftPanelDate,
this.rightPanelDate = new Date(leftPanelDate.getFullYear(), leftPanelDate.getMonth() + 1, leftPanelDate.getDate());
}
this.rangeState = { this.rangeState = {
from: this.dates[0], from: this.dates[0],
to: this.dates[1], to: this.dates[1],
selecting: false selecting: false
}; };
// set panels positioning
const leftPanelDate = this.startDate || this.dates[0] || new Date();
this.leftPanelDate = leftPanelDate;
const rightPanelDate = new Date(leftPanelDate.getFullYear(), leftPanelDate.getMonth() + 1, leftPanelDate.getDate());
this.rightPanelDate = this.splitPanels ? new Date(Math.max(this.dates[1], rightPanelDate)) : rightPanelDate;
// reset stuff
this.currentView = this.selectionMode || 'range';
this.leftPickerTable = `${this.currentView}-table`;
this.rightPickerTable = `${this.currentView}-table`;
}, },
currentView(currentView){ currentView(currentView){
const leftMonth = this.leftPanelDate.getMonth(); const leftMonth = this.leftPanelDate.getMonth();
const rightMonth = this.rightPanelDate.getMonth(); const rightMonth = this.rightPanelDate.getMonth();
const isSameYear = this.leftPanelDate.getFullYear() === this.rightPanelDate.getFullYear(); const isSameYear = this.leftPanelDate.getFullYear() === this.rightPanelDate.getFullYear();
this.leftPickerTable = `${currentView}-table`;
this.rightPickerTable = `${currentView}-table`;
if (currentView === 'date' && isSameYear && leftMonth === rightMonth){ if (currentView === 'date' && isSameYear && leftMonth === rightMonth){
this.changePanelDate('right', 'Month', 1); this.changePanelDate('right', 'Month', 1);
} }
@ -214,6 +219,10 @@
if (currentView === 'year' && isSameYear){ if (currentView === 'year' && isSameYear){
this.changePanelDate('right', 'FullYear', 10); this.changePanelDate('right', 'FullYear', 10);
} }
},
selectionMode(type){
console.log('Selection type change!', type);
this.currentView = type || 'range';
} }
}, },
methods: { methods: {

View file

@ -139,9 +139,10 @@
value (newVal) { value (newVal) {
this.dates = newVal; this.dates = newVal;
if (JSON.stringify(newVal) === '[null]') this.panelDate = this.startDate || new Date(); if (JSON.stringify(newVal) === '[null]') this.panelDate = this.startDate || new Date();
},
selectionMode(){ // reset stuff
this.currentView = this.selectionMode; this.currentView = this.selectionMode;
this.pickerTable = this.getTableType(this.currentView);
}, },
currentView (currentView) { currentView (currentView) {
this.$emit('on-selection-mode-change', currentView); this.$emit('on-selection-mode-change', currentView);

View file

@ -237,6 +237,7 @@
}, },
handleBlur () { handleBlur () {
this.visible = false; this.visible = false;
this.internalValue = this.internalValue.slice(); // trigger panel watchers to reset views
}, },
handleInputChange (event) { handleInputChange (event) {
const isArrayValue = this.type.includes('range') || this.multiple; const isArrayValue = this.type.includes('range') || this.multiple;