diff --git a/src/components/UncontrolledTabs.js b/src/components/UncontrolledTabs.js index ae8a14172b..18cd248626 100644 --- a/src/components/UncontrolledTabs.js +++ b/src/components/UncontrolledTabs.js @@ -19,12 +19,20 @@ function isTabDisabled(node) { return node.getAttribute('aria-disabled') === 'true'; } -const canUseActiveElement = !!( - typeof window !== 'undefined' && - window.document && - window.document.activeElement -); - +let canUseActiveElement; +try { + canUseActiveElement = !!( + typeof window !== 'undefined' && + window.document && + window.document.activeElement + ); +} catch (e) { + // Work around for IE bug when accessing document.activeElement in an iframe + // Refer to the following resources: + // http://stackoverflow.com/a/10982960/369687 + // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12733599 + canUseActiveElement = false; +} export default class UncontrolledTabs extends Component { static defaultProps = { className: 'react-tabs', diff --git a/src/components/__tests__/Tabs-node-test.js b/src/components/__tests__/Tabs-node-test.js new file mode 100644 index 0000000000..13387621a2 --- /dev/null +++ b/src/components/__tests__/Tabs-node-test.js @@ -0,0 +1,44 @@ +/** + * @jest-environment node + */ +/* eslint-env jest */ +import React from 'react'; +import Tab from '../Tab'; +import TabList from '../TabList'; +import TabPanel from '../TabPanel'; +import Tabs from '../Tabs'; +import { reset as resetIdCounter } from '../../helpers/uuid'; + +function createTabs(props = {}) { + return ( + + + Foo + Bar + + Baz + + Qux + + Hello Foo + Hello Bar + Hello Baz + Hello Qux + + ); +} + +describe('ServerSide ', () => { + beforeEach(() => resetIdCounter()); + + beforeAll(() => { + // eslint-disable-next-line no-console + console.error = error => { + throw new Error(error); + }; + }); + + test('does not crash in node environments', () => { + expect(() => createTabs()).not.toThrow(); + }); +});