Skip to content

Commit f6f0bdf

Browse files
michaelwnelsondanez
authored andcommitted
fix(tabs): Fix activeElement check #193 (#194)
* Fix activeElement check #193 * Add test and fix check
1 parent ea55f8c commit f6f0bdf

File tree

2 files changed

+58
-6
lines changed

2 files changed

+58
-6
lines changed

Diff for: src/components/UncontrolledTabs.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,20 @@ function isTabDisabled(node) {
1919
return node.getAttribute('aria-disabled') === 'true';
2020
}
2121

22-
const canUseActiveElement = !!(
23-
typeof window !== 'undefined' &&
24-
window.document &&
25-
window.document.activeElement
26-
);
27-
22+
let canUseActiveElement;
23+
try {
24+
canUseActiveElement = !!(
25+
typeof window !== 'undefined' &&
26+
window.document &&
27+
window.document.activeElement
28+
);
29+
} catch (e) {
30+
// Work around for IE bug when accessing document.activeElement in an iframe
31+
// Refer to the following resources:
32+
// http://stackoverflow.com/a/10982960/369687
33+
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12733599
34+
canUseActiveElement = false;
35+
}
2836
export default class UncontrolledTabs extends Component {
2937
static defaultProps = {
3038
className: 'react-tabs',

Diff for: src/components/__tests__/Tabs-node-test.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @jest-environment node
3+
*/
4+
/* eslint-env jest */
5+
import React from 'react';
6+
import Tab from '../Tab';
7+
import TabList from '../TabList';
8+
import TabPanel from '../TabPanel';
9+
import Tabs from '../Tabs';
10+
import { reset as resetIdCounter } from '../../helpers/uuid';
11+
12+
function createTabs(props = {}) {
13+
return (
14+
<Tabs {...props}>
15+
<TabList>
16+
<Tab>Foo</Tab>
17+
<Tab>Bar</Tab>
18+
<Tab>
19+
<a>Baz</a>
20+
</Tab>
21+
<Tab disabled>Qux</Tab>
22+
</TabList>
23+
<TabPanel>Hello Foo</TabPanel>
24+
<TabPanel>Hello Bar</TabPanel>
25+
<TabPanel>Hello Baz</TabPanel>
26+
<TabPanel>Hello Qux</TabPanel>
27+
</Tabs>
28+
);
29+
}
30+
31+
describe('ServerSide <Tabs />', () => {
32+
beforeEach(() => resetIdCounter());
33+
34+
beforeAll(() => {
35+
// eslint-disable-next-line no-console
36+
console.error = error => {
37+
throw new Error(error);
38+
};
39+
});
40+
41+
test('does not crash in node environments', () => {
42+
expect(() => createTabs()).not.toThrow();
43+
});
44+
});

0 commit comments

Comments
 (0)