Commit 939a162ad73c1fe49260941684c2e02c8d63b5c1

Authored by Sergio Crisostomo
1 parent e9d7ff50

Prevent selecting disabled dates

src/components/date-picker/base/date-table.vue
... ... @@ -7,7 +7,7 @@
7 7 </div>
8 8 <span
9 9 :class="getCellCls(cell)"
10   - v-for="(cell, i) in readCells"
  10 + v-for="(cell, i) in cells"
11 11 :key="String(cell.date) + i"
12 12 @click="handleClick(cell, $event)"
13 13 @mouseenter="handleMouseMove(cell)"
... ... @@ -61,7 +61,7 @@
61 61 const weekDays = translatedDays.splice(weekStartDay, 7 - weekStartDay).concat(translatedDays.splice(0, weekStartDay));
62 62 return this.showWeekNumbers ? [''].concat(weekDays) : weekDays;
63 63 },
64   - readCells () {
  64 + cells () {
65 65 const tableYear = this.tableDate.getFullYear();
66 66 const tableMonth = this.tableDate.getMonth();
67 67 const today = clearHours(new Date()); // timestamp of today
... ...
src/components/date-picker/base/mixin.js
... ... @@ -2,6 +2,7 @@
2 2 import {clearHours} from '../util';
3 3  
4 4 export default {
  5 + name: 'PanelTable',
5 6 props: {
6 7 tableDate: {
7 8 type: Date,
... ...
src/components/date-picker/picker.vue
... ... @@ -385,7 +385,15 @@
385 385 if (this.type.match(/range/)){
386 386 this.$refs.pickerPanel.handleRangePick(this.focusedDate, 'date');
387 387 } else {
388   - this.onPick(this.focusedDate, false, 'date');
  388 + const panels = findComponentsDownward(this, 'PanelTable');
  389 + const compareDate = (d) => {
  390 + const sliceIndex = ['year', 'month', 'date'].indexOf((this.type)) + 1;
  391 + return [d.getFullYear(), d.getMonth(), d.getDate()].slice(0, sliceIndex).join('-');
  392 + };
  393 + const dateIsValid = panels.find(({cells}) => {
  394 + return cells.find(({date, disabled}) => compareDate(date) === compareDate(this.focusedDate) && !disabled);
  395 + });
  396 + if (dateIsValid) this.onPick(this.focusedDate, false, 'date');
389 397 }
390 398 }
391 399  
... ...
src/styles/components/date-picker.less
... ... @@ -46,7 +46,7 @@
46 46 }
47 47 &-cell:hover, &-focused{
48 48 em{
49   - background: @date-picker-cell-hover-bg;
  49 + background: @date-picker-cell-hover-bg !important;
50 50 }
51 51 }
52 52  
... ...