@@ -112,15 +112,24 @@ export default {
112
112
* Returns the currently focused cell element, if there is one...
113
113
*/
114
114
getActiveCell () {
115
- const isActiveElementACell = this .hasClass (document .activeElement , ' cell' )
116
- const isOnSameView = this .hasClass (document .activeElement , this .view )
115
+ const activeElement = this .getActiveElement ()
116
+ const isActiveElementACell = this .hasClass (activeElement, ' cell' )
117
+ const isOnSameView = this .hasClass (activeElement, this .view )
117
118
118
119
if (isActiveElementACell && isOnSameView && ! this .resetTabbableCell ) {
119
- return document . activeElement
120
+ return activeElement
120
121
}
121
122
122
123
return null
123
124
},
125
+ /**
126
+ * Returns the currently focused element, using shadowRoot for web-components...
127
+ */
128
+ getActiveElement () {
129
+ return document .activeElement .shadowRoot
130
+ ? document .activeElement .shadowRoot .activeElement
131
+ : document .activeElement
132
+ },
124
133
/**
125
134
* Returns the `cellId` for a given a date
126
135
* @param {Date} date The date for which we need the cellId
@@ -333,9 +342,10 @@ export default {
333
342
return false
334
343
}
335
344
345
+ const activeElement = this .getActiveElement ()
336
346
const firstNavElement = this .navElements [0 ]
337
347
338
- return document . activeElement === firstNavElement
348
+ return activeElement === firstNavElement
339
349
},
340
350
/**
341
351
* Used for inline calendars; returns true if the user tabs forwards from the last focusable element
@@ -347,9 +357,10 @@ export default {
347
357
return false
348
358
}
349
359
360
+ const activeElement = this .getActiveElement ()
350
361
const lastNavElement = this .navElements [this .navElements .length - 1 ]
351
362
352
- return document . activeElement === lastNavElement
363
+ return activeElement === lastNavElement
353
364
},
354
365
/**
355
366
* Resets the focus to the open date
@@ -453,8 +464,10 @@ export default {
453
464
* Keeps track of the currently focused index in the navElements array
454
465
*/
455
466
setNavElementsFocusedIndex () {
467
+ const activeElement = this .getActiveElement ()
468
+
456
469
for (let i = 0 ; i < this .navElements .length ; i += 1 ) {
457
- if (document . activeElement === this .navElements [i]) {
470
+ if (activeElement === this .navElements [i]) {
458
471
this .navElementsFocusedIndex = i
459
472
return
460
473
}
@@ -575,7 +588,8 @@ export default {
575
588
tabToCorrectInlineCell () {
576
589
const lastElement = this .getLastInlineFocusableElement ()
577
590
const isACell = this .hasClass (lastElement, ' cell' )
578
- const isLastElementFocused = document .activeElement === lastElement
591
+ const activeElement = this .getActiveElement ()
592
+ const isLastElementFocused = activeElement === lastElement
579
593
580
594
// If there are no focusable elements in the footer slots and the inline datepicker has been tabbed to (backwards)
581
595
if (isACell && isLastElementFocused) {
@@ -585,8 +599,7 @@ export default {
585
599
586
600
// If `show-header` is false and the inline datepicker has been tabbed to (forwards)
587
601
this .$nextTick (() => {
588
- const isFirstCell =
589
- document .activeElement .getAttribute (' data-id' ) === ' 0'
602
+ const isFirstCell = activeElement .getAttribute (' data-id' ) === ' 0'
590
603
591
604
if (isFirstCell) {
592
605
this .focusInlineTabbableCell ()
@@ -597,7 +610,8 @@ export default {
597
610
* Update which cell in the picker should be focus-trapped
598
611
*/
599
612
updateTabbableCell () {
600
- const isActiveElementACell = this .hasClass (document .activeElement , ' cell' )
613
+ const activeElement = this .getActiveElement ()
614
+ const isActiveElementACell = this .hasClass (activeElement, ' cell' )
601
615
const needToUpdate = ! this .tabbableCell || isActiveElementACell
602
616
603
617
if (needToUpdate) {
0 commit comments