Skip to content

Commit 7eb770a

Browse files
committed
Move resetCounter to main package
1 parent 0a15604 commit 7eb770a

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/components/Tabs.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import PropTypes from 'prop-types';
22
import React, { cloneElement, Component } from 'react';
33
import cx from 'classnames';
4-
import uuid, { reset } from '../helpers/uuid';
4+
import uuid from '../helpers/uuid';
55
import childrenPropType from '../helpers/childrenPropType';
66
import Tab from './Tab';
7+
import TabList from './TabList';
8+
import TabPanel from './TabPanel';
79

810
// Determine if a node from event.target is a Tab element
911
function isTabNode(node) {
@@ -43,10 +45,6 @@ export default class Tabs extends Component {
4345
this.state = Tabs.copyPropsToState(this.props, this.state);
4446
}
4547

46-
static resetIDCounter() {
47-
reset();
48-
}
49-
5048
getChildContext() {
5149
return {
5250
forceRenderTabPanel: this.props.forceRenderTabPanel,
@@ -148,7 +146,6 @@ export default class Tabs extends Component {
148146

149147
getChildren() {
150148
let index = 0;
151-
let count = 0;
152149
const children = this.props.children;
153150
const state = this.state;
154151
this.tabIds = this.tabIds || [];
@@ -171,10 +168,10 @@ export default class Tabs extends Component {
171168
return null;
172169
}
173170

174-
let result = null;
171+
let result = child;
175172

176173
// Clone TabList and Tab components to have refs
177-
if (count++ === 0) {
174+
if (child.type === TabList) {
178175
// TODO try setting the uuid in the "constructor" for `Tab`/`TabPanel`
179176
result = cloneElement(child, {
180177
children: React.Children.map(child.props.children, (tab) => {
@@ -211,7 +208,7 @@ export default class Tabs extends Component {
211208

212209
// Reset index for panels
213210
index = 0;
214-
} else {
211+
} else if (child.type === TabPanel) {
215212
const id = this.panelIds[index];
216213
const tabId = this.tabIds[index];
217214
const selected = state.selectedIndex === index;

src/components/__tests__/Tabs-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Tab from '../Tab';
66
import TabList from '../TabList';
77
import TabPanel from '../TabPanel';
88
import Tabs from '../Tabs';
9+
import { reset as resetIdCounter } from '../../helpers/uuid';
910

1011
function createTabs(props = {
1112
selectedIndex: 0,
@@ -113,7 +114,7 @@ describe('<Tabs />', () => {
113114
it('should reset ids correctly', () => {
114115
mount(createTabs());
115116

116-
Tabs.resetIDCounter();
117+
resetIdCounter();
117118

118119
const wrapper = mount(createTabs());
119120
const tablist = wrapper.childAt(0);

src/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import Tabs from './components/Tabs';
22
import TabList from './components/TabList';
33
import Tab from './components/Tab';
44
import TabPanel from './components/TabPanel';
5+
import { reset as resetIdCounter } from './helpers/uuid';
56

67
export {
78
Tab,
89
TabList,
910
TabPanel,
1011
Tabs,
12+
resetIdCounter,
1113
};

0 commit comments

Comments
 (0)