Commit c2b7fed05fc774d4f681625ee3f6a6759d818bd7

Authored by Sergio Crisostomo
1 parent 15457562

Reset panel selectionMode and positioning on blur

src/components/date-picker/panel/Date/date-range.vue
... ... @@ -185,26 +185,31 @@
185 185 const minDate = newVal[0] ? toDate(newVal[0]) : null;
186 186 const maxDate = newVal[1] ? toDate(newVal[1]) : null;
187 187 this.dates = [minDate, maxDate].sort();
188   - if (JSON.stringify(this.dates) === '[null,null]') {
189   - const leftPanelDate = this.startDate || new Date();
190   - this.leftPanelDate = leftPanelDate,
191   - this.rightPanelDate = new Date(leftPanelDate.getFullYear(), leftPanelDate.getMonth() + 1, leftPanelDate.getDate());
192   - }
193 188  
194 189 this.rangeState = {
195 190 from: this.dates[0],
196 191 to: this.dates[1],
197 192 selecting: false
198 193 };
  194 +
  195 +
  196 + // set panels positioning
  197 + const leftPanelDate = this.startDate || this.dates[0] || new Date();
  198 + this.leftPanelDate = leftPanelDate;
  199 + const rightPanelDate = new Date(leftPanelDate.getFullYear(), leftPanelDate.getMonth() + 1, leftPanelDate.getDate());
  200 + this.rightPanelDate = this.splitPanels ? new Date(Math.max(this.dates[1], rightPanelDate)) : rightPanelDate;
  201 +
  202 + // reset stuff
  203 + this.currentView = this.selectionMode || 'range';
  204 + this.leftPickerTable = `${this.currentView}-table`;
  205 + this.rightPickerTable = `${this.currentView}-table`;
  206 +
199 207 },
200 208 currentView(currentView){
201 209 const leftMonth = this.leftPanelDate.getMonth();
202 210 const rightMonth = this.rightPanelDate.getMonth();
203 211 const isSameYear = this.leftPanelDate.getFullYear() === this.rightPanelDate.getFullYear();
204 212  
205   - this.leftPickerTable = `${currentView}-table`;
206   - this.rightPickerTable = `${currentView}-table`;
207   -
208 213 if (currentView === 'date' && isSameYear && leftMonth === rightMonth){
209 214 this.changePanelDate('right', 'Month', 1);
210 215 }
... ... @@ -214,6 +219,10 @@
214 219 if (currentView === 'year' && isSameYear){
215 220 this.changePanelDate('right', 'FullYear', 10);
216 221 }
  222 + },
  223 + selectionMode(type){
  224 + console.log('Selection type change!', type);
  225 + this.currentView = type || 'range';
217 226 }
218 227 },
219 228 methods: {
... ...
src/components/date-picker/panel/Date/date.vue
... ... @@ -139,9 +139,10 @@
139 139 value (newVal) {
140 140 this.dates = newVal;
141 141 if (JSON.stringify(newVal) === '[null]') this.panelDate = this.startDate || new Date();
142   - },
143   - selectionMode(){
  142 +
  143 + // reset stuff
144 144 this.currentView = this.selectionMode;
  145 + this.pickerTable = this.getTableType(this.currentView);
145 146 },
146 147 currentView (currentView) {
147 148 this.$emit('on-selection-mode-change', currentView);
... ...
src/components/date-picker/picker.vue
... ... @@ -237,6 +237,7 @@
237 237 },
238 238 handleBlur () {
239 239 this.visible = false;
  240 + this.internalValue = this.internalValue.slice(); // trigger panel watchers to reset views
240 241 },
241 242 handleInputChange (event) {
242 243 const isArrayValue = this.type.includes('range') || this.multiple;
... ...