Skip to content

Commit

Permalink
fix(tabs): Fix activeElement check #193 (#194)
Browse files Browse the repository at this point in the history
* Fix activeElement check #193

* Add test and fix check
  • Loading branch information
michaelwnelson authored and danez committed Sep 5, 2017
1 parent df6aec7 commit 722d52f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/components/UncontrolledTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
44 changes: 44 additions & 0 deletions src/components/__tests__/Tabs-node-test.js
Original file line number Diff line number Diff line change
@@ -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 (
<Tabs {...props}>
<TabList>
<Tab>Foo</Tab>
<Tab>Bar</Tab>
<Tab>
<a>Baz</a>
</Tab>
<Tab disabled>Qux</Tab>
</TabList>
<TabPanel>Hello Foo</TabPanel>
<TabPanel>Hello Bar</TabPanel>
<TabPanel>Hello Baz</TabPanel>
<TabPanel>Hello Qux</TabPanel>
</Tabs>
);
}

describe('ServerSide <Tabs />', () => {
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();
});
});

0 comments on commit 722d52f

Please sign in to comment.