@@ -22,18 +22,24 @@ function isTabDisabled(node) {
22
22
}
23
23
24
24
let canUseActiveElement ;
25
- try {
26
- canUseActiveElement = ! ! (
27
- typeof window !== 'undefined' &&
28
- window . document &&
29
- window . document . activeElement
30
- ) ;
31
- } catch ( e ) {
32
- // Work around for IE bug when accessing document.activeElement in an iframe
33
- // Refer to the following resources:
34
- // http://stackoverflow.com/a/10982960/369687
35
- // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12733599
36
- canUseActiveElement = false ;
25
+
26
+ function determineCanUseActiveElement ( environment ) {
27
+ const env =
28
+ environment || ( typeof window !== 'undefined' ? window : undefined ) ;
29
+
30
+ try {
31
+ canUseActiveElement = ! ! (
32
+ typeof env !== 'undefined' &&
33
+ env . document &&
34
+ env . document . activeElement
35
+ ) ;
36
+ } catch ( e ) {
37
+ // Work around for IE bug when accessing document.activeElement in an iframe
38
+ // Refer to the following resources:
39
+ // http://stackoverflow.com/a/10982960/369687
40
+ // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12733599
41
+ canUseActiveElement = false ;
42
+ }
37
43
}
38
44
export default class UncontrolledTabs extends Component {
39
45
static defaultProps = {
@@ -57,6 +63,7 @@ export default class UncontrolledTabs extends Component {
57
63
selectedIndex : PropTypes . number . isRequired ,
58
64
selectedTabClassName : PropTypes . string ,
59
65
selectedTabPanelClassName : PropTypes . string ,
66
+ environment : PropTypes . object ,
60
67
} ;
61
68
62
69
tabNodes = [ ] ;
@@ -164,6 +171,7 @@ export default class UncontrolledTabs extends Component {
164
171
selectedIndex,
165
172
selectedTabClassName,
166
173
selectedTabPanelClassName,
174
+ environment,
167
175
} = this . props ;
168
176
169
177
this . tabIds = this . tabIds || [ ] ;
@@ -190,10 +198,19 @@ export default class UncontrolledTabs extends Component {
190
198
// If it is we should keep the focus on the next selected tab
191
199
let wasTabFocused = false ;
192
200
201
+ if ( canUseActiveElement == null ) {
202
+ determineCanUseActiveElement ( environment ) ;
203
+ }
204
+
193
205
if ( canUseActiveElement ) {
194
206
wasTabFocused = React . Children . toArray ( child . props . children )
195
207
. filter ( isTab )
196
- . some ( ( tab , i ) => document . activeElement === this . getTab ( i ) ) ;
208
+ . some ( ( tab , i ) => {
209
+ const env =
210
+ environment ||
211
+ ( typeof window !== 'undefined' ? window : undefined ) ;
212
+ return env && env . document . activeElement === this . getTab ( i ) ;
213
+ } ) ;
197
214
}
198
215
199
216
result = cloneElement ( child , {
@@ -350,6 +367,7 @@ export default class UncontrolledTabs extends Component {
350
367
selectedIndex, // unused
351
368
selectedTabClassName, // unused
352
369
selectedTabPanelClassName, // unused
370
+ environment, // unused
353
371
...attributes
354
372
} = this . props ;
355
373
0 commit comments