@@ -9,6 +9,7 @@ export default {
9
9
},
10
10
navElements: [],
11
11
navElementsFocusedIndex: 0 ,
12
+ resetTabbableCell: false ,
12
13
tabbableCell: null ,
13
14
}
14
15
},
@@ -39,6 +40,19 @@ export default {
39
40
}
40
41
}
41
42
},
43
+ /**
44
+ * Returns the currently focused cell element, if there is one...
45
+ */
46
+ getActiveCell () {
47
+ const isActiveElementACell = this .hasClass (document .activeElement , ' cell' )
48
+ const isOnSameView = this .hasClass (document .activeElement , this .view )
49
+
50
+ if (isActiveElementACell && isOnSameView && ! this .resetTabbableCell ) {
51
+ return document .activeElement
52
+ }
53
+
54
+ return null
55
+ },
42
56
/**
43
57
* Returns true if the calendar has been passed the given slot
44
58
* @param {String} slotName The name of the slot
@@ -162,13 +176,17 @@ export default {
162
176
return
163
177
}
164
178
179
+ this .tabbableCell = null
180
+ this .resetTabbableCell = true
181
+
165
182
this .$nextTick (() => {
166
- this .setTabbableCell ()
167
183
this .setNavElements ()
168
184
169
185
setTimeout (() => {
170
186
this .applyFocus ()
171
187
}, this .focus .delay )
188
+
189
+ this .resetTabbableCell = false
172
190
})
173
191
},
174
192
/**
@@ -191,6 +209,8 @@ export default {
191
209
setNavElements () {
192
210
if (! this .view ) return
193
211
212
+ this .updateTabbableCell ()
213
+
194
214
const view = this .ucFirst (this .view )
195
215
196
216
this .navElements = [
@@ -230,6 +250,7 @@ export default {
230
250
const pickerCells = this .$refs .picker .$refs .cells .$el
231
251
232
252
this .tabbableCell =
253
+ this .getActiveCell () ||
233
254
pickerCells .querySelector (' button.selected:not(.muted):enabled' ) ||
234
255
pickerCells .querySelector (' button.open:not(.muted):enabled' ) ||
235
256
pickerCells .querySelector (' button.today:not(.muted):enabled' ) ||
@@ -276,6 +297,17 @@ export default {
276
297
this .tabForwards ()
277
298
}
278
299
},
300
+ /**
301
+ * Update which cell in the picker should be focus-trapped
302
+ */
303
+ updateTabbableCell () {
304
+ const isActiveElementACell = this .hasClass (document .activeElement , ' cell' )
305
+ const needToUpdate = ! this .tabbableCell || isActiveElementACell
306
+
307
+ if (needToUpdate) {
308
+ this .setTabbableCell ()
309
+ }
310
+ },
279
311
},
280
312
}
281
313
</script >
0 commit comments