Skip to content

Commit 58fb270

Browse files
authored
Fix document usage in server environments (#175)
1 parent 5b59ad8 commit 58fb270

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/components/UncontrolledTabs.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ function isTabDisabled(node) {
1818
return node.getAttribute('aria-disabled') === 'true';
1919
}
2020

21+
const canUseActiveElement = !!(typeof window !== 'undefined' &&
22+
window.document &&
23+
window.document.activeElement);
24+
2125
export default class UncontrolledTabs extends Component {
2226
static defaultProps = {
2327
className: 'ReactTabs',
@@ -143,10 +147,14 @@ export default class UncontrolledTabs extends Component {
143147

144148
// Figure out if the current focus in the DOM is set on a Tab
145149
// If it is we should keep the focus on the next selected tab
146-
const wasTabFocused = React.Children
147-
.toArray(child.props.children)
148-
.filter(tab => tab.type === Tab)
149-
.some((tab, i) => document.activeElement === this.getTab(i));
150+
let wasTabFocused = false;
151+
152+
if (canUseActiveElement) {
153+
wasTabFocused = React.Children
154+
.toArray(child.props.children)
155+
.filter(tab => tab.type === Tab)
156+
.some((tab, i) => document.activeElement === this.getTab(i));
157+
}
150158

151159
result = cloneElement(child, {
152160
children: React.Children.map(child.props.children, tab => {

0 commit comments

Comments
 (0)