Skip to content

Commit 88721f8

Browse files
committed
Allow reseting counter for isomorphic apps
1 parent 9b71c44 commit 88721f8

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/components/Tabs.js

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

@@ -43,6 +43,10 @@ export default class Tabs extends Component {
4343
this.state = Tabs.copyPropsToState(this.props, this.state);
4444
}
4545

46+
static resetIDCounter() {
47+
reset();
48+
}
49+
4650
getChildContext() {
4751
return {
4852
forceRenderTabPanel: this.props.forceRenderTabPanel,

src/components/__tests__/Tabs-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,23 @@ describe('<Tabs />', () => {
109109
expect(panel.prop('id')).toBe(tab.prop('panelId'));
110110
}
111111
});
112+
113+
it('should reset ids correctly', () => {
114+
mount(createTabs());
115+
116+
Tabs.resetIDCounter();
117+
118+
const wrapper = mount(createTabs());
119+
const tablist = wrapper.childAt(0);
120+
121+
for (let i = 0, j = 0, l = wrapper.instance().getTabsCount(); i < l; i++, j += 2) {
122+
const tab = tablist.childAt(i);
123+
const panel = wrapper.childAt(i + 1);
124+
125+
expect(tab.prop('id')).toBe(`react-tabs-${j}`);
126+
expect(panel.prop('id')).toBe(`react-tabs-${j + 1}`);
127+
}
128+
});
112129
});
113130

114131
describe('interaction', () => {

src/helpers/uuid.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// Get a universally unique identifier
22
let count = 0;
3-
module.exports = function uuid() {
3+
export default function uuid() {
44
return `react-tabs-${count++}`;
5-
};
5+
}
6+
7+
export function reset() {
8+
count = 0;
9+
}

0 commit comments

Comments
 (0)