@@ -48,6 +48,23 @@ export default {
48
48
},
49
49
},
50
50
methods: {
51
+ /**
52
+ * Converts a date to first in month for `month` view or first in year for `year` view
53
+ * @param {Date} date The date to convert
54
+ * @returns {Date}
55
+ */
56
+ getCellDate (date ) {
57
+ switch (this .view ) {
58
+ case ' month' :
59
+ return new Date (this .utils .setDate (date, 1 ))
60
+ case ' year' :
61
+ return new Date (
62
+ this .utils .setMonth (new Date (this .utils .setDate (date, 1 )), 0 ),
63
+ )
64
+ default :
65
+ return date
66
+ }
67
+ },
51
68
/**
52
69
* Returns true, unless tabbing should be focus-trapped
53
70
* @return {Boolean}
@@ -104,6 +121,27 @@ export default {
104
121
105
122
return null
106
123
},
124
+ /**
125
+ * Returns the `cellId` for a given a date
126
+ * @param {Date} date The date for which we need the cellId
127
+ * @returns {Number|null}
128
+ */
129
+ getCellId (date ) {
130
+ if (! date || ! this .$refs .picker .$refs .cells ) {
131
+ return null
132
+ }
133
+
134
+ const cellDate = this .getCellDate (date)
135
+ const { cells } = this .$refs .picker .$refs .cells
136
+
137
+ for (let i = 0 ; i < cells .length ; i += 1 ) {
138
+ if (cells[i].timestamp === cellDate .valueOf ()) {
139
+ return i
140
+ }
141
+ }
142
+
143
+ return null
144
+ },
107
145
/**
108
146
* Finds an element by its `ref` attribute
109
147
* @param {string} ref The `ref` name of the wanted element
@@ -205,6 +243,18 @@ export default {
205
243
206
244
return this .$refs .dateInput .$refs [this .refName ]
207
245
},
246
+ /**
247
+ * Used for a typeable datepicker: returns the cell element that corresponds to latestValidTypedDate...
248
+ */
249
+ getTypedCell () {
250
+ if (! this .typeable ) {
251
+ return null
252
+ }
253
+
254
+ const cellId = this .getCellId (this .latestValidTypedDate )
255
+
256
+ return cellId ? this .$refs .picker .$refs .cells .$el .children [cellId] : null
257
+ },
208
258
/**
209
259
* Sets `datepickerId` (as a global) and keeps track of focusable elements
210
260
*/
@@ -426,6 +476,7 @@ export default {
426
476
427
477
this .tabbableCell =
428
478
this .getActiveCell () ||
479
+ this .getTypedCell () ||
429
480
pickerCells .querySelector (' button.selected:not(.muted):enabled' ) ||
430
481
pickerCells .querySelector (' button.open:not(.muted):enabled' ) ||
431
482
pickerCells .querySelector (' button.today:not(.muted):enabled' ) ||
0 commit comments